Skip to content

Commit 9dc6858

Browse files
committed
Parallelize test_sql.py - added explicit teardown in each pytest connectable fixture
1 parent 21fabbc commit 9dc6858

File tree

1 file changed

+23
-41
lines changed

1 file changed

+23
-41
lines changed

pandas/tests/io/test_sql.py

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ def mysql_pymysql_engine_types(mysql_pymysql_engine, types_data):
710710
def mysql_pymysql_conn(mysql_pymysql_engine):
711711
with mysql_pymysql_engine.connect() as conn:
712712
yield conn
713+
conn.close()
713714

714715

715716
@pytest.fixture
@@ -724,6 +725,7 @@ def mysql_pymysql_conn_iris(mysql_pymysql_engine_iris):
724725
def mysql_pymysql_conn_types(mysql_pymysql_engine_types):
725726
with mysql_pymysql_engine_types.connect() as conn:
726727
yield conn
728+
conn.close()
727729

728730

729731
@pytest.fixture
@@ -765,6 +767,7 @@ def postgresql_psycopg2_engine_types(postgresql_psycopg2_engine, types_data):
765767
def postgresql_psycopg2_conn(postgresql_psycopg2_engine):
766768
with postgresql_psycopg2_engine.connect() as conn:
767769
yield conn
770+
conn.close()
768771

769772

770773
@pytest.fixture
@@ -776,6 +779,7 @@ def postgresql_adbc_conn():
776779
uri = "postgresql://postgres:postgres@localhost:5432/pandas"
777780
with dbapi.connect(uri) as conn:
778781
yield conn
782+
conn.close()
779783

780784

781785
@pytest.fixture
@@ -793,7 +797,6 @@ def postgresql_adbc_iris(request, postgresql_adbc_conn, iris_path):
793797
create_and_load_iris_view(conn, iris_table_uuid, iris_view_uuid)
794798

795799
yield conn, iris_table_uuid, iris_view_uuid
796-
conn.drop()
797800

798801

799802
@pytest.fixture
@@ -814,8 +817,9 @@ def postgresql_psycopg2_conn_iris(postgresql_psycopg2_engine_iris):
814817

815818
@pytest.fixture
816819
def postgresql_psycopg2_conn_types(postgresql_psycopg2_engine_types):
817-
with postgresql_psycopg2_engine_types.connect() as conn:
818-
yield conn
820+
conn = postgresql_psycopg2_engine_types.connect()
821+
yield conn
822+
conn.close()
819823

820824

821825
@pytest.fixture
@@ -835,11 +839,11 @@ def sqlite_engine(sqlite_str):
835839

836840
@pytest.fixture
837841
def sqlite_conn(sqlite_engine):
838-
with sqlite_engine.connect() as conn:
839-
try:
840-
yield conn
841-
finally:
842-
conn.close()
842+
conn = sqlite_engine.connect()
843+
try:
844+
yield conn
845+
finally:
846+
conn.close()
843847

844848

845849
@pytest.fixture
@@ -864,11 +868,11 @@ def sqlite_engine_iris(request, iris_path, sqlite_engine):
864868
uuid_root = f"{calling_test_name}_" + f"{uuid.uuid4().hex}"[0:10]
865869
iris_table_uuid = "tbl_" + uuid_root
866870
iris_view_uuid = "view_" + uuid_root
867-
conn = sqlite_engine
871+
engine = sqlite_engine
868872

869-
create_and_load_iris_sqlite3(conn, iris_path, iris_table_uuid)
870-
create_and_load_iris_view(conn, iris_table_uuid, iris_view_uuid)
871-
yield conn, iris_table_uuid, iris_view_uuid
873+
create_and_load_iris_sqlite3(engine, iris_path, iris_table_uuid)
874+
create_and_load_iris_view(engine, iris_table_uuid, iris_view_uuid)
875+
yield engine, iris_table_uuid, iris_view_uuid
872876

873877

874878
@pytest.fixture
@@ -958,12 +962,11 @@ def sqlite_buildin_iris(request, sqlite_buildin, iris_path):
958962
uuid_root = f"{calling_test_name}_" + f"{uuid.uuid4().hex}"[0:10]
959963
iris_table_uuid = "tbl_" + uuid_root
960964
iris_view_uuid = "view_" + uuid_root
961-
conn = sqlite3.connect(":memory:")
965+
conn = sqlite_buildin
962966

963967
create_and_load_iris_sqlite3(conn, iris_path, iris_table_uuid)
964968
create_and_load_iris_view(conn, iris_table_uuid, iris_view_uuid)
965969
yield conn, iris_table_uuid, iris_view_uuid
966-
# conn.close()
967970

968971

969972
@pytest.fixture
@@ -1065,14 +1068,12 @@ def iris_connect_and_per_test_id(request, iris_path):
10651068
conn_name = request.param[0]
10661069

10671070
conn, table_uuid, view_uuid = request.getfixturevalue(conn_name)
1068-
10691071
yield {
10701072
"conn": conn,
10711073
"iris_table_uuid": table_uuid,
10721074
"iris_view_uuid": view_uuid,
10731075
"conn_name": conn_name,
10741076
}
1075-
sqlalchemy = pytest.importorskip("sqlalchemy")
10761077
if isinstance(conn, str):
10771078
conn = sqlalchemy.create_engine(conn)
10781079
drop_view(view_uuid, conn)
@@ -1081,13 +1082,6 @@ def iris_connect_and_per_test_id(request, iris_path):
10811082
else:
10821083
drop_view(view_uuid, conn)
10831084
drop_table(table_uuid, conn)
1084-
if isinstance(conn, sqlalchemy.Engine):
1085-
conn.dispose()
1086-
if isinstance(conn, sqlalchemy.Connection):
1087-
Engine = conn.engine
1088-
conn.close()
1089-
Engine.dispose()
1090-
10911085

10921086

10931087
connectables_to_create_uuid_function_map = {
@@ -1203,17 +1197,11 @@ def connect_and_uuid_types(request, types_data):
12031197
"conn_name": conn_name,
12041198
}
12051199
if isinstance(conn, str):
1206-
conn = sqlalchemy.create_engine(conn)
1207-
drop_table_uuid_views(conn, table_uuid, view_uuid)
1208-
conn.dispose()
1200+
engine = sqlalchemy.create_engine(conn)
1201+
drop_table_uuid_views(engine, table_uuid, view_uuid)
1202+
engine.dispose()
12091203
else:
12101204
drop_table_uuid_views(conn, table_uuid, view_uuid)
1211-
if isinstance(conn, sqlalchemy.Engine):
1212-
conn.dispose()
1213-
if isinstance(conn, sqlalchemy.Connection):
1214-
Engine = conn.engine
1215-
conn.close()
1216-
Engine.dispose()
12171205

12181206

12191207
@pytest.fixture
@@ -1232,17 +1220,11 @@ def connect_and_uuid(request, types_data):
12321220
"conn_name": conn_name,
12331221
}
12341222
if isinstance(conn, str):
1235-
conn = sqlalchemy.create_engine(conn)
1236-
drop_table_uuid_views(conn, table_uuid, view_uuid)
1237-
conn.dispose()
1223+
engine = sqlalchemy.create_engine(conn)
1224+
drop_table_uuid_views(engine, table_uuid, view_uuid)
1225+
engine.dispose()
12381226
else:
12391227
drop_table_uuid_views(conn, table_uuid, view_uuid)
1240-
if isinstance(conn, sqlalchemy.Engine):
1241-
conn.dispose()
1242-
if isinstance(conn, sqlalchemy.Connection):
1243-
Engine = conn.engine
1244-
conn.close()
1245-
Engine.dispose()
12461228

12471229

12481230

0 commit comments

Comments
 (0)