@@ -253,9 +253,13 @@ def _get_exec(self):
253
253
else :
254
254
return self .conn .cursor ()
255
255
256
- def _load_iris_data (self , datapath ):
256
+ @pytest .fixture (params = [('io' , 'data' , 'iris.csv' )])
257
+ def load_iris_data (self , datapath , request ):
257
258
import io
258
- iris_csv_file = datapath ('io' , 'data' , 'iris.csv' )
259
+ iris_csv_file = datapath (* request .param )
260
+
261
+ if not hasattr (self , 'conn' ):
262
+ self .setup_connect ()
259
263
260
264
self .drop_table ('iris' )
261
265
self ._get_exec ().execute (SQL_STRINGS ['create_iris' ][self .flavor ])
@@ -503,10 +507,14 @@ class _TestSQLApi(PandasSQLTest):
503
507
flavor = 'sqlite'
504
508
mode = None
505
509
506
- @pytest .fixture (autouse = True )
507
- def setup_method (self , datapath ):
510
+ def setup_connect (self ):
508
511
self .conn = self .connect ()
509
- self ._load_iris_data (datapath )
512
+
513
+ @pytest .fixture (autouse = True )
514
+ def setup_method (self , load_iris_data ):
515
+ self .load_test_data_and_sql ()
516
+
517
+ def load_test_data_and_sql (self ):
510
518
self ._load_iris_view ()
511
519
self ._load_test1_data ()
512
520
self ._load_test2_data ()
@@ -1027,8 +1035,8 @@ class _EngineToConnMixin(object):
1027
1035
"""
1028
1036
1029
1037
@pytest .fixture (autouse = True )
1030
- def setup_method (self , datapath ):
1031
- super (_EngineToConnMixin , self ).setup_method ( datapath )
1038
+ def setup_method (self , load_iris_data ):
1039
+ super (_EngineToConnMixin , self ).load_test_data_and_sql ( )
1032
1040
engine = self .conn
1033
1041
conn = engine .connect ()
1034
1042
self .__tx = conn .begin ()
@@ -1153,14 +1161,14 @@ def setup_class(cls):
1153
1161
msg = "{0} - can't connect to {1} server" .format (cls , cls .flavor )
1154
1162
pytest .skip (msg )
1155
1163
1156
- @pytest .fixture (autouse = True )
1157
- def setup_method (self , datapath ):
1158
- self .setup_connect ()
1159
-
1160
- self ._load_iris_data (datapath )
1164
+ def load_test_data_and_sql (self ):
1161
1165
self ._load_raw_sql ()
1162
1166
self ._load_test1_data ()
1163
1167
1168
+ @pytest .fixture (autouse = True )
1169
+ def setup_method (self , load_iris_data ):
1170
+ self .load_test_data_and_sql ()
1171
+
1164
1172
@classmethod
1165
1173
def setup_import (cls ):
1166
1174
# Skip this test if SQLAlchemy not available
@@ -1925,15 +1933,17 @@ class TestSQLiteFallback(SQLiteMixIn, PandasSQLTest):
1925
1933
def connect (cls ):
1926
1934
return sqlite3 .connect (':memory:' )
1927
1935
1928
- @pytest .fixture (autouse = True )
1929
- def setup_method (self , datapath ):
1936
+ def setup_connect (self ):
1930
1937
self .conn = self .connect ()
1931
- self .pandasSQL = sql .SQLiteDatabase (self .conn )
1932
-
1933
- self ._load_iris_data (datapath )
1934
1938
1939
+ def load_test_data_and_sql (self ):
1940
+ self .pandasSQL = sql .SQLiteDatabase (self .conn )
1935
1941
self ._load_test1_data ()
1936
1942
1943
+ @pytest .fixture (autouse = True )
1944
+ def setup_method (self , load_iris_data ):
1945
+ self .load_test_data_and_sql ()
1946
+
1937
1947
def test_read_sql (self ):
1938
1948
self ._read_sql_iris ()
1939
1949
@@ -2151,6 +2161,12 @@ def setup_method(self, request, datapath):
2151
2161
self .method = request .function
2152
2162
self .conn = sqlite3 .connect (':memory:' )
2153
2163
2164
+ # In some test cases we may close db connection
2165
+ # Re-open conn here so we can perform cleanup in teardown
2166
+ yield
2167
+ self .method = request .function
2168
+ self .conn = sqlite3 .connect (':memory:' )
2169
+
2154
2170
def test_basic (self ):
2155
2171
frame = tm .makeTimeDataFrame ()
2156
2172
self ._check_roundtrip (frame )
@@ -2227,7 +2243,7 @@ def test_execute_fail(self):
2227
2243
with pytest .raises (Exception ):
2228
2244
sql .execute ('INSERT INTO test VALUES("foo", "bar", 7)' , self .conn )
2229
2245
2230
- def test_execute_closed_connection (self , request , datapath ):
2246
+ def test_execute_closed_connection (self ):
2231
2247
create_sql = """
2232
2248
CREATE TABLE test
2233
2249
(
@@ -2246,9 +2262,6 @@ def test_execute_closed_connection(self, request, datapath):
2246
2262
with pytest .raises (Exception ):
2247
2263
tquery ("select * from test" , con = self .conn )
2248
2264
2249
- # Initialize connection again (needed for tearDown)
2250
- self .setup_method (request , datapath )
2251
-
2252
2265
def test_na_roundtrip (self ):
2253
2266
pass
2254
2267
0 commit comments