Skip to content

Commit d154650

Browse files
datapythonistaPingviinituutti
authored andcommitted
TST: Making explicit when we run the db tests (pandas-dev#24450)
1 parent eefe623 commit d154650

10 files changed

+43
-90
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ matrix:
3434
include:
3535
- dist: trusty
3636
env:
37-
- JOB="3.7" ENV_FILE="ci/deps/travis-37.yaml" PATTERN="not slow and not network"
37+
- JOB="3.7" ENV_FILE="ci/deps/travis-37.yaml" PATTERN="not slow and not network and not db"
3838

3939
- dist: trusty
4040
env:

ci/azure/posix.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,37 @@ jobs:
1212
py35_np_120:
1313
ENV_FILE: ci/deps/azure-macos-35.yaml
1414
CONDA_PY: "35"
15-
PATTERN: "not slow and not network"
15+
PATTERN: "not slow and not network and not db"
1616

1717
${{ if eq(parameters.name, 'Linux') }}:
1818
py27_np_120:
1919
ENV_FILE: ci/deps/azure-27-compat.yaml
2020
CONDA_PY: "27"
21-
PATTERN: "not slow and not network"
21+
PATTERN: "not slow and not network and not db"
2222

2323
py27_locale_slow_old_np:
2424
ENV_FILE: ci/deps/azure-27-locale.yaml
2525
CONDA_PY: "27"
26-
PATTERN: "slow"
26+
PATTERN: "slow and not db"
2727
LOCALE_OVERRIDE: "zh_CN.UTF-8"
2828
EXTRA_APT: "language-pack-zh-hans"
2929

3030
py36_locale_slow:
3131
ENV_FILE: ci/deps/azure-36-locale_slow.yaml
3232
CONDA_PY: "36"
33-
PATTERN: "not slow and not network"
33+
PATTERN: "not slow and not network and not db"
3434
LOCALE_OVERRIDE: "it_IT.UTF-8"
3535

3636
py37_locale:
3737
ENV_FILE: ci/deps/azure-37-locale.yaml
3838
CONDA_PY: "37"
39-
PATTERN: "not slow and not network"
39+
PATTERN: "not slow and not network and not db"
4040
LOCALE_OVERRIDE: "zh_CN.UTF-8"
4141

4242
py37_np_dev:
4343
ENV_FILE: ci/deps/azure-37-numpydev.yaml
4444
CONDA_PY: "37"
45-
PATTERN: "not slow and not network"
45+
PATTERN: "not slow and not network and not db"
4646
TEST_ARGS: "-W error"
4747
PANDAS_TESTING_MODE: "deprecate"
4848
EXTRA_APT: "xsel"

ci/azure/windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
displayName: 'Build'
3939
- script: |
4040
call activate pandas-dev
41-
pytest -m "not slow and not network" --junitxml=test-data.xml pandas -n 2 -r sxX --strict --durations=10 %*
41+
pytest -m "not slow and not network and not db" --junitxml=test-data.xml pandas -n 2 -r sxX --strict --durations=10 %*
4242
displayName: 'Test'
4343
- task: PublishTestResults@2
4444
inputs:

ci/deps/azure-27-compat.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ dependencies:
99
- numexpr=2.6.1
1010
- numpy=1.12.0
1111
- openpyxl=2.5.5
12-
- psycopg2
1312
- pytables=3.4.2
1413
- python-dateutil=2.5.0
1514
- python=2.7*
1615
- pytz=2013b
1716
- scipy=0.18.1
18-
- sqlalchemy=0.7.8
1917
- xlrd=1.0.0
2018
- xlsxwriter=0.5.2
2119
- xlwt=0.7.5
@@ -25,5 +23,4 @@ dependencies:
2523
- pip:
2624
- html5lib==1.0b2
2725
- beautifulsoup4==4.2.1
28-
- pymysql==0.6.0
2926
- hypothesis>=3.58.0

ci/deps/azure-36-locale_slow.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ dependencies:
1515
- numexpr
1616
- numpy
1717
- openpyxl
18-
- psycopg2
19-
- pymysql
2018
- pytables
2119
- python-dateutil
2220
- python=3.6*
2321
- pytz
2422
- s3fs
2523
- scipy
26-
- sqlalchemy
2724
- xarray
2825
- xlrd
2926
- xlsxwriter

ci/deps/azure-37-locale.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ dependencies:
1414
- numexpr
1515
- numpy
1616
- openpyxl
17-
- psycopg2
18-
- pymysql
1917
- pytables
2018
- python-dateutil
2119
- python=3.7*
2220
- pytz
2321
- s3fs
2422
- scipy
25-
- sqlalchemy
2623
- xarray
2724
- xlrd
2825
- xlsxwriter

pandas/conftest.py

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def pytest_addoption(parser):
3434
help="skip slow tests")
3535
parser.addoption("--skip-network", action="store_true",
3636
help="skip network tests")
37+
parser.addoption("--skip-db", action="store_true",
38+
help="skip db tests")
3739
parser.addoption("--run-high-memory", action="store_true",
3840
help="run high memory tests")
3941
parser.addoption("--only-slow", action="store_true",
@@ -52,6 +54,9 @@ def pytest_runtest_setup(item):
5254
if 'network' in item.keywords and item.config.getoption("--skip-network"):
5355
pytest.skip("skipping due to --skip-network")
5456

57+
if 'db' in item.keywords and item.config.getoption("--skip-db"):
58+
pytest.skip("skipping due to --skip-db")
59+
5560
if 'high_memory' in item.keywords and not item.config.getoption(
5661
"--run-high-memory"):
5762
pytest.skip(

pandas/tests/io/test_sql.py

+28-72
Original file line numberDiff line numberDiff line change
@@ -1175,14 +1175,8 @@ class _TestSQLAlchemy(SQLAlchemyMixIn, PandasSQLTest):
11751175
def setup_class(cls):
11761176
cls.setup_import()
11771177
cls.setup_driver()
1178-
1179-
# test connection
1180-
try:
1181-
conn = cls.connect()
1182-
conn.connect()
1183-
except sqlalchemy.exc.OperationalError:
1184-
msg = "{0} - can't connect to {1} server".format(cls, cls.flavor)
1185-
pytest.skip(msg)
1178+
conn = cls.connect()
1179+
conn.connect()
11861180

11871181
def load_test_data_and_sql(self):
11881182
self._load_raw_sql()
@@ -1820,13 +1814,10 @@ def connect(cls):
18201814

18211815
@classmethod
18221816
def setup_driver(cls):
1823-
try:
1824-
import pymysql # noqa
1825-
cls.driver = 'pymysql'
1826-
from pymysql.constants import CLIENT
1827-
cls.connect_args = {'client_flag': CLIENT.MULTI_STATEMENTS}
1828-
except ImportError:
1829-
pytest.skip('pymysql not installed')
1817+
pymysql = pytest.importorskip('pymysql')
1818+
cls.driver = 'pymysql'
1819+
cls.connect_args = {
1820+
'client_flag': pymysql.constants.CLIENT.MULTI_STATEMENTS}
18301821

18311822
def test_default_type_conversion(self):
18321823
df = sql.read_sql_table("types_test_data", self.conn)
@@ -1889,11 +1880,8 @@ def connect(cls):
18891880

18901881
@classmethod
18911882
def setup_driver(cls):
1892-
try:
1893-
import psycopg2 # noqa
1894-
cls.driver = 'psycopg2'
1895-
except ImportError:
1896-
pytest.skip('psycopg2 not installed')
1883+
pytest.importorskip('psycopg2')
1884+
cls.driver = 'psycopg2'
18971885

18981886
def test_schema_support(self):
18991887
# only test this for postgresql (schema's not supported in
@@ -1991,21 +1979,25 @@ def psql_insert_copy(table, conn, keys, data_iter):
19911979

19921980

19931981
@pytest.mark.single
1982+
@pytest.mark.db
19941983
class TestMySQLAlchemy(_TestMySQLAlchemy, _TestSQLAlchemy):
19951984
pass
19961985

19971986

19981987
@pytest.mark.single
1988+
@pytest.mark.db
19991989
class TestMySQLAlchemyConn(_TestMySQLAlchemy, _TestSQLAlchemyConn):
20001990
pass
20011991

20021992

20031993
@pytest.mark.single
1994+
@pytest.mark.db
20041995
class TestPostgreSQLAlchemy(_TestPostgreSQLAlchemy, _TestSQLAlchemy):
20051996
pass
20061997

20071998

20081999
@pytest.mark.single
2000+
@pytest.mark.db
20092001
class TestPostgreSQLAlchemyConn(_TestPostgreSQLAlchemy, _TestSQLAlchemyConn):
20102002
pass
20112003

@@ -2248,13 +2240,6 @@ def tquery(query, con=None, cur=None):
22482240
return list(res)
22492241

22502242

2251-
def _skip_if_no_pymysql():
2252-
try:
2253-
import pymysql # noqa
2254-
except ImportError:
2255-
pytest.skip('pymysql not installed, skipping')
2256-
2257-
22582243
@pytest.mark.single
22592244
class TestXSQLite(SQLiteMixIn):
22602245

@@ -2463,76 +2448,56 @@ def clean_up(test_table_to_drop):
24632448

24642449

24652450
@pytest.mark.single
2451+
@pytest.mark.db
24662452
@pytest.mark.skip(reason="gh-13611: there is no support for MySQL "
24672453
"if SQLAlchemy is not installed")
24682454
class TestXMySQL(MySQLMixIn):
24692455

24702456
@pytest.fixture(autouse=True, scope='class')
24712457
def setup_class(cls):
2472-
_skip_if_no_pymysql()
2473-
2474-
# test connection
2475-
import pymysql
2476-
try:
2477-
# Try Travis defaults.
2478-
# No real user should allow root access with a blank password.
2479-
pymysql.connect(host='localhost', user='root', passwd='',
2480-
db='pandas_nosetest')
2481-
except pymysql.Error:
2482-
pass
2483-
else:
2484-
return
2458+
pymysql = pytest.importorskip('pymysql')
2459+
pymysql.connect(host='localhost', user='root', passwd='',
2460+
db='pandas_nosetest')
24852461
try:
24862462
pymysql.connect(read_default_group='pandas')
24872463
except pymysql.ProgrammingError:
2488-
pytest.skip(
2464+
raise RuntimeError(
24892465
"Create a group of connection parameters under the heading "
24902466
"[pandas] in your system's mysql default file, "
2491-
"typically located at ~/.my.cnf or /etc/.my.cnf. ")
2467+
"typically located at ~/.my.cnf or /etc/.my.cnf.")
24922468
except pymysql.Error:
2493-
pytest.skip(
2469+
raise RuntimeError(
24942470
"Cannot connect to database. "
24952471
"Create a group of connection parameters under the heading "
24962472
"[pandas] in your system's mysql default file, "
2497-
"typically located at ~/.my.cnf or /etc/.my.cnf. ")
2473+
"typically located at ~/.my.cnf or /etc/.my.cnf.")
24982474

24992475
@pytest.fixture(autouse=True)
25002476
def setup_method(self, request, datapath):
2501-
_skip_if_no_pymysql()
2502-
import pymysql
2477+
pymysql = pytest.importorskip('pymysql')
2478+
pymysql.connect(host='localhost', user='root', passwd='',
2479+
db='pandas_nosetest')
25032480
try:
2504-
# Try Travis defaults.
2505-
# No real user should allow root access with a blank password.
2506-
self.conn = pymysql.connect(host='localhost', user='root',
2507-
passwd='', db='pandas_nosetest')
2508-
except pymysql.Error:
2509-
pass
2510-
else:
2511-
return
2512-
try:
2513-
self.conn = pymysql.connect(read_default_group='pandas')
2481+
pymysql.connect(read_default_group='pandas')
25142482
except pymysql.ProgrammingError:
2515-
pytest.skip(
2483+
raise RuntimeError(
25162484
"Create a group of connection parameters under the heading "
25172485
"[pandas] in your system's mysql default file, "
2518-
"typically located at ~/.my.cnf or /etc/.my.cnf. ")
2486+
"typically located at ~/.my.cnf or /etc/.my.cnf.")
25192487
except pymysql.Error:
2520-
pytest.skip(
2488+
raise RuntimeError(
25212489
"Cannot connect to database. "
25222490
"Create a group of connection parameters under the heading "
25232491
"[pandas] in your system's mysql default file, "
2524-
"typically located at ~/.my.cnf or /etc/.my.cnf. ")
2492+
"typically located at ~/.my.cnf or /etc/.my.cnf.")
25252493

25262494
self.method = request.function
25272495

25282496
def test_basic(self):
2529-
_skip_if_no_pymysql()
25302497
frame = tm.makeTimeDataFrame()
25312498
self._check_roundtrip(frame)
25322499

25332500
def test_write_row_by_row(self):
2534-
2535-
_skip_if_no_pymysql()
25362501
frame = tm.makeTimeDataFrame()
25372502
frame.iloc[0, 0] = np.nan
25382503
drop_sql = "DROP TABLE IF EXISTS test"
@@ -2552,7 +2517,6 @@ def test_write_row_by_row(self):
25522517
tm.assert_frame_equal(result, frame, check_less_precise=True)
25532518

25542519
def test_chunksize_read_type(self):
2555-
_skip_if_no_pymysql()
25562520
frame = tm.makeTimeDataFrame()
25572521
frame.index.name = "index"
25582522
drop_sql = "DROP TABLE IF EXISTS test"
@@ -2567,7 +2531,6 @@ def test_chunksize_read_type(self):
25672531
tm.assert_frame_equal(frame[:chunksize], chunk_df)
25682532

25692533
def test_execute(self):
2570-
_skip_if_no_pymysql()
25712534
frame = tm.makeTimeDataFrame()
25722535
drop_sql = "DROP TABLE IF EXISTS test"
25732536
create_sql = sql.get_schema(frame, 'test')
@@ -2587,7 +2550,6 @@ def test_execute(self):
25872550
tm.assert_frame_equal(result, frame[:1])
25882551

25892552
def test_schema(self):
2590-
_skip_if_no_pymysql()
25912553
frame = tm.makeTimeDataFrame()
25922554
create_sql = sql.get_schema(frame, 'test')
25932555
lines = create_sql.splitlines()
@@ -2607,7 +2569,6 @@ def test_schema(self):
26072569

26082570
@tm.capture_stdout
26092571
def test_execute_fail(self):
2610-
_skip_if_no_pymysql()
26112572
drop_sql = "DROP TABLE IF EXISTS test"
26122573
create_sql = """
26132574
CREATE TABLE test
@@ -2629,7 +2590,6 @@ def test_execute_fail(self):
26292590
sql.execute('INSERT INTO test VALUES("foo", "bar", 7)', self.conn)
26302591

26312592
def test_execute_closed_connection(self, request, datapath):
2632-
_skip_if_no_pymysql()
26332593
drop_sql = "DROP TABLE IF EXISTS test"
26342594
create_sql = """
26352595
CREATE TABLE test
@@ -2654,11 +2614,9 @@ def test_execute_closed_connection(self, request, datapath):
26542614
self.setup_method(request, datapath)
26552615

26562616
def test_na_roundtrip(self):
2657-
_skip_if_no_pymysql()
26582617
pass
26592618

26602619
def _check_roundtrip(self, frame):
2661-
_skip_if_no_pymysql()
26622620
drop_sql = "DROP TABLE IF EXISTS test_table"
26632621
cur = self.conn.cursor()
26642622
with warnings.catch_warnings():
@@ -2695,13 +2653,11 @@ def _check_roundtrip(self, frame):
26952653
tm.assert_frame_equal(expected, result)
26962654

26972655
def test_keyword_as_column_names(self):
2698-
_skip_if_no_pymysql()
26992656
df = DataFrame({'From': np.ones(5)})
27002657
sql.to_sql(df, con=self.conn, name='testkeywords',
27012658
if_exists='replace', index=False)
27022659

27032660
def test_if_exists(self):
2704-
_skip_if_no_pymysql()
27052661
df_if_exists_1 = DataFrame({'col1': [1, 2], 'col2': ['A', 'B']})
27062662
df_if_exists_2 = DataFrame(
27072663
{'col1': [3, 4, 5], 'col2': ['C', 'D', 'E']})

pandas/util/_tester.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test(extra_args=None):
1616
import hypothesis # noqa
1717
except ImportError:
1818
raise ImportError("Need hypothesis>=3.58 to run tests")
19-
cmd = ['--skip-slow', '--skip-network']
19+
cmd = ['--skip-slow', '--skip-network', '--skip-db']
2020
if extra_args:
2121
if not isinstance(extra_args, list):
2222
extra_args = [extra_args]

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ markers =
6767
single: mark a test as single cpu only
6868
slow: mark a test as slow
6969
network: mark a test as network
70+
db: tests requiring a database (mysql or postgres)
7071
high_memory: mark a test as a high-memory only
7172
clipboard: mark a pd.read_clipboard test
7273
doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL

0 commit comments

Comments
 (0)