Skip to content

Commit 0c51e04

Browse files
committed
Make test_sql.py sqlite_engine tests parallelizable
1 parent ecb6c4d commit 0c51e04

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pandas/tests/io/test_sql.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,12 +3848,13 @@ def test_read_sql_dtype(conn, request, func, dtype_backend):
38483848

38493849
def test_bigint_warning(sqlite_engine):
38503850
conn = sqlite_engine
3851+
table_uuid = table_uuid_gen("test_bigintwarning")
38513852
# test no warning for BIGINT (to support int64) is raised (GH7433)
38523853
df = DataFrame({"a": [1, 2]}, dtype="int64")
3853-
assert df.to_sql(name="test_bigintwarning", con=conn, index=False) == 2
3854+
assert df.to_sql(name=table_uuid, con=conn, index=False) == 2
38543855

38553856
with tm.assert_produces_warning(None):
3856-
sql.read_sql_table("test_bigintwarning", conn)
3857+
sql.read_sql_table(table_uuid, conn)
38573858

38583859

38593860
def test_valueerror_exception(sqlite_engine):
@@ -3865,6 +3866,7 @@ def test_valueerror_exception(sqlite_engine):
38653866

38663867
def test_row_object_is_named_tuple(sqlite_engine):
38673868
conn = sqlite_engine
3869+
table_uuid = table_uuid_gen("test_frame")
38683870
# GH 40682
38693871
# Test for the is_named_tuple() function
38703872
# Placed here due to its usage of sqlalchemy
@@ -3882,7 +3884,7 @@ def test_row_object_is_named_tuple(sqlite_engine):
38823884
BaseModel = declarative_base()
38833885

38843886
class Test(BaseModel):
3885-
__tablename__ = "test_frame"
3887+
__tablename__ = table_uuid
38863888
id = Column(Integer, primary_key=True)
38873889
string_column = Column(String(50))
38883890

@@ -3892,7 +3894,7 @@ class Test(BaseModel):
38923894
with Session() as session:
38933895
df = DataFrame({"id": [0, 1], "string_column": ["hello", "world"]})
38943896
assert (
3895-
df.to_sql(name="test_frame", con=conn, index=False, if_exists="replace")
3897+
df.to_sql(name=table_uuid, con=conn, index=False, if_exists="replace")
38963898
== 2
38973899
)
38983900
session.commit()
@@ -3905,7 +3907,7 @@ class Test(BaseModel):
39053907
def test_read_sql_string_inference(sqlite_engine):
39063908
conn = sqlite_engine
39073909
# GH#54430
3908-
table = "test"
3910+
table = table_uuid_gen("test")
39093911
df = DataFrame({"a": ["x", "y"]})
39103912
df.to_sql(table, con=conn, index=False, if_exists="replace")
39113913

@@ -3922,10 +3924,11 @@ def test_read_sql_string_inference(sqlite_engine):
39223924

39233925
def test_roundtripping_datetimes(sqlite_engine):
39243926
conn = sqlite_engine
3927+
table_uuid = table_uuid_gen("test")
39253928
# GH#54877
39263929
df = DataFrame({"t": [datetime(2020, 12, 31, 12)]}, dtype="datetime64[ns]")
3927-
df.to_sql("test", conn, if_exists="replace", index=False)
3928-
result = pd.read_sql("select * from test", conn).iloc[0, 0]
3930+
df.to_sql(table_uuid, conn, if_exists="replace", index=False)
3931+
result = pd.read_sql(f"select * from {table_uuid}", conn).iloc[0, 0]
39293932
assert result == "2020-12-31 12:00:00.000000"
39303933

39313934

@@ -4061,17 +4064,18 @@ def test_self_join_date_columns(postgresql_psycopg2_engine):
40614064

40624065
def test_create_and_drop_table(sqlite_engine):
40634066
conn = sqlite_engine
4067+
table_uuid = table_uuid_gen("drop_test_frame")
40644068
temp_frame = DataFrame({"one": [1.0, 2.0, 3.0, 4.0], "two": [4.0, 3.0, 2.0, 1.0]})
40654069
with sql.SQLDatabase(conn) as pandasSQL:
40664070
with pandasSQL.run_transaction():
4067-
assert pandasSQL.to_sql(temp_frame, "drop_test_frame") == 4
4071+
assert pandasSQL.to_sql(temp_frame, table_uuid) == 4
40684072

4069-
assert pandasSQL.has_table("drop_test_frame")
4073+
assert pandasSQL.has_table(table_uuid)
40704074

40714075
with pandasSQL.run_transaction():
4072-
pandasSQL.drop_table("drop_test_frame")
4076+
pandasSQL.drop_table(table_uuid)
40734077

4074-
assert not pandasSQL.has_table("drop_test_frame")
4078+
assert not pandasSQL.has_table(table_uuid)
40754079

40764080

40774081
def test_sqlite_datetime_date(sqlite_buildin):

0 commit comments

Comments
 (0)