@@ -1175,14 +1175,8 @@ class _TestSQLAlchemy(SQLAlchemyMixIn, PandasSQLTest):
1175
1175
def setup_class (cls ):
1176
1176
cls .setup_import ()
1177
1177
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 ()
1186
1180
1187
1181
def load_test_data_and_sql (self ):
1188
1182
self ._load_raw_sql ()
@@ -1820,13 +1814,10 @@ def connect(cls):
1820
1814
1821
1815
@classmethod
1822
1816
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 }
1830
1821
1831
1822
def test_default_type_conversion (self ):
1832
1823
df = sql .read_sql_table ("types_test_data" , self .conn )
@@ -1889,11 +1880,8 @@ def connect(cls):
1889
1880
1890
1881
@classmethod
1891
1882
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'
1897
1885
1898
1886
def test_schema_support (self ):
1899
1887
# only test this for postgresql (schema's not supported in
@@ -1991,21 +1979,25 @@ def psql_insert_copy(table, conn, keys, data_iter):
1991
1979
1992
1980
1993
1981
@pytest .mark .single
1982
+ @pytest .mark .db
1994
1983
class TestMySQLAlchemy (_TestMySQLAlchemy , _TestSQLAlchemy ):
1995
1984
pass
1996
1985
1997
1986
1998
1987
@pytest .mark .single
1988
+ @pytest .mark .db
1999
1989
class TestMySQLAlchemyConn (_TestMySQLAlchemy , _TestSQLAlchemyConn ):
2000
1990
pass
2001
1991
2002
1992
2003
1993
@pytest .mark .single
1994
+ @pytest .mark .db
2004
1995
class TestPostgreSQLAlchemy (_TestPostgreSQLAlchemy , _TestSQLAlchemy ):
2005
1996
pass
2006
1997
2007
1998
2008
1999
@pytest .mark .single
2000
+ @pytest .mark .db
2009
2001
class TestPostgreSQLAlchemyConn (_TestPostgreSQLAlchemy , _TestSQLAlchemyConn ):
2010
2002
pass
2011
2003
@@ -2248,13 +2240,6 @@ def tquery(query, con=None, cur=None):
2248
2240
return list (res )
2249
2241
2250
2242
2251
- def _skip_if_no_pymysql ():
2252
- try :
2253
- import pymysql # noqa
2254
- except ImportError :
2255
- pytest .skip ('pymysql not installed, skipping' )
2256
-
2257
-
2258
2243
@pytest .mark .single
2259
2244
class TestXSQLite (SQLiteMixIn ):
2260
2245
@@ -2463,76 +2448,56 @@ def clean_up(test_table_to_drop):
2463
2448
2464
2449
2465
2450
@pytest .mark .single
2451
+ @pytest .mark .db
2466
2452
@pytest .mark .skip (reason = "gh-13611: there is no support for MySQL "
2467
2453
"if SQLAlchemy is not installed" )
2468
2454
class TestXMySQL (MySQLMixIn ):
2469
2455
2470
2456
@pytest .fixture (autouse = True , scope = 'class' )
2471
2457
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' )
2485
2461
try :
2486
2462
pymysql .connect (read_default_group = 'pandas' )
2487
2463
except pymysql .ProgrammingError :
2488
- pytest . skip (
2464
+ raise RuntimeError (
2489
2465
"Create a group of connection parameters under the heading "
2490
2466
"[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." )
2492
2468
except pymysql .Error :
2493
- pytest . skip (
2469
+ raise RuntimeError (
2494
2470
"Cannot connect to database. "
2495
2471
"Create a group of connection parameters under the heading "
2496
2472
"[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." )
2498
2474
2499
2475
@pytest .fixture (autouse = True )
2500
2476
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' )
2503
2480
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' )
2514
2482
except pymysql .ProgrammingError :
2515
- pytest . skip (
2483
+ raise RuntimeError (
2516
2484
"Create a group of connection parameters under the heading "
2517
2485
"[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." )
2519
2487
except pymysql .Error :
2520
- pytest . skip (
2488
+ raise RuntimeError (
2521
2489
"Cannot connect to database. "
2522
2490
"Create a group of connection parameters under the heading "
2523
2491
"[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." )
2525
2493
2526
2494
self .method = request .function
2527
2495
2528
2496
def test_basic (self ):
2529
- _skip_if_no_pymysql ()
2530
2497
frame = tm .makeTimeDataFrame ()
2531
2498
self ._check_roundtrip (frame )
2532
2499
2533
2500
def test_write_row_by_row (self ):
2534
-
2535
- _skip_if_no_pymysql ()
2536
2501
frame = tm .makeTimeDataFrame ()
2537
2502
frame .iloc [0 , 0 ] = np .nan
2538
2503
drop_sql = "DROP TABLE IF EXISTS test"
@@ -2552,7 +2517,6 @@ def test_write_row_by_row(self):
2552
2517
tm .assert_frame_equal (result , frame , check_less_precise = True )
2553
2518
2554
2519
def test_chunksize_read_type (self ):
2555
- _skip_if_no_pymysql ()
2556
2520
frame = tm .makeTimeDataFrame ()
2557
2521
frame .index .name = "index"
2558
2522
drop_sql = "DROP TABLE IF EXISTS test"
@@ -2567,7 +2531,6 @@ def test_chunksize_read_type(self):
2567
2531
tm .assert_frame_equal (frame [:chunksize ], chunk_df )
2568
2532
2569
2533
def test_execute (self ):
2570
- _skip_if_no_pymysql ()
2571
2534
frame = tm .makeTimeDataFrame ()
2572
2535
drop_sql = "DROP TABLE IF EXISTS test"
2573
2536
create_sql = sql .get_schema (frame , 'test' )
@@ -2587,7 +2550,6 @@ def test_execute(self):
2587
2550
tm .assert_frame_equal (result , frame [:1 ])
2588
2551
2589
2552
def test_schema (self ):
2590
- _skip_if_no_pymysql ()
2591
2553
frame = tm .makeTimeDataFrame ()
2592
2554
create_sql = sql .get_schema (frame , 'test' )
2593
2555
lines = create_sql .splitlines ()
@@ -2607,7 +2569,6 @@ def test_schema(self):
2607
2569
2608
2570
@tm .capture_stdout
2609
2571
def test_execute_fail (self ):
2610
- _skip_if_no_pymysql ()
2611
2572
drop_sql = "DROP TABLE IF EXISTS test"
2612
2573
create_sql = """
2613
2574
CREATE TABLE test
@@ -2629,7 +2590,6 @@ def test_execute_fail(self):
2629
2590
sql .execute ('INSERT INTO test VALUES("foo", "bar", 7)' , self .conn )
2630
2591
2631
2592
def test_execute_closed_connection (self , request , datapath ):
2632
- _skip_if_no_pymysql ()
2633
2593
drop_sql = "DROP TABLE IF EXISTS test"
2634
2594
create_sql = """
2635
2595
CREATE TABLE test
@@ -2654,11 +2614,9 @@ def test_execute_closed_connection(self, request, datapath):
2654
2614
self .setup_method (request , datapath )
2655
2615
2656
2616
def test_na_roundtrip (self ):
2657
- _skip_if_no_pymysql ()
2658
2617
pass
2659
2618
2660
2619
def _check_roundtrip (self , frame ):
2661
- _skip_if_no_pymysql ()
2662
2620
drop_sql = "DROP TABLE IF EXISTS test_table"
2663
2621
cur = self .conn .cursor ()
2664
2622
with warnings .catch_warnings ():
@@ -2695,13 +2653,11 @@ def _check_roundtrip(self, frame):
2695
2653
tm .assert_frame_equal (expected , result )
2696
2654
2697
2655
def test_keyword_as_column_names (self ):
2698
- _skip_if_no_pymysql ()
2699
2656
df = DataFrame ({'From' : np .ones (5 )})
2700
2657
sql .to_sql (df , con = self .conn , name = 'testkeywords' ,
2701
2658
if_exists = 'replace' , index = False )
2702
2659
2703
2660
def test_if_exists (self ):
2704
- _skip_if_no_pymysql ()
2705
2661
df_if_exists_1 = DataFrame ({'col1' : [1 , 2 ], 'col2' : ['A' , 'B' ]})
2706
2662
df_if_exists_2 = DataFrame (
2707
2663
{'col1' : [3 , 4 , 5 ], 'col2' : ['C' , 'D' , 'E' ]})
0 commit comments