@@ -748,10 +748,9 @@ def postgresql_psycopg2_conn_types(postgresql_psycopg2_engine_types):
748
748
749
749
750
750
@pytest .fixture
751
- def sqlite_str ():
751
+ def sqlite_str (temp_file ):
752
752
pytest .importorskip ("sqlalchemy" )
753
- with tm .ensure_clean () as name :
754
- yield f"sqlite:///{ name } "
753
+ return f"sqlite:///{ temp_file } "
755
754
756
755
757
756
@pytest .fixture
@@ -817,20 +816,19 @@ def sqlite_conn_types(sqlite_engine_types):
817
816
818
817
819
818
@pytest .fixture
820
- def sqlite_adbc_conn ():
819
+ def sqlite_adbc_conn (temp_file ):
821
820
pytest .importorskip ("pyarrow" )
822
821
pytest .importorskip ("adbc_driver_sqlite" )
823
822
from adbc_driver_sqlite import dbapi
824
823
825
- with tm .ensure_clean () as name :
826
- uri = f"file:{ name } "
827
- with dbapi .connect (uri ) as conn :
828
- yield conn
829
- for view in get_all_views (conn ):
830
- drop_view (view , conn )
831
- for tbl in get_all_tables (conn ):
832
- drop_table (tbl , conn )
833
- conn .commit ()
824
+ uri = f"file:{ temp_file } "
825
+ with dbapi .connect (uri ) as conn :
826
+ yield conn
827
+ for view in get_all_views (conn ):
828
+ drop_view (view , conn )
829
+ for tbl in get_all_tables (conn ):
830
+ drop_table (tbl , conn )
831
+ conn .commit ()
834
832
835
833
836
834
@pytest .fixture
@@ -2504,20 +2502,20 @@ def test_sqlalchemy_integer_overload_mapping(conn, request, integer):
2504
2502
sql .SQLTable ("test_type" , db , frame = df )
2505
2503
2506
2504
2507
- def test_database_uri_string (request , test_frame1 ):
2505
+ def test_database_uri_string (temp_file , request , test_frame1 ):
2508
2506
pytest .importorskip ("sqlalchemy" )
2509
2507
# Test read_sql and .to_sql method with a database URI (GH10654)
2510
2508
# db_uri = 'sqlite:///:memory:' # raises
2511
2509
# sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near
2512
2510
# "iris": syntax error [SQL: 'iris']
2513
- with tm . ensure_clean () as name :
2514
- db_uri = "sqlite:///" + name
2515
- table = "iris"
2516
- test_frame1 .to_sql (name = table , con = db_uri , if_exists = "replace" , index = False )
2517
- test_frame2 = sql .read_sql (table , db_uri )
2518
- test_frame3 = sql .read_sql_table (table , db_uri )
2519
- query = "SELECT * FROM iris"
2520
- test_frame4 = sql .read_sql_query (query , db_uri )
2511
+ name = str ( temp_file )
2512
+ db_uri = "sqlite:///" + name
2513
+ table = "iris"
2514
+ test_frame1 .to_sql (name = table , con = db_uri , if_exists = "replace" , index = False )
2515
+ test_frame2 = sql .read_sql (table , db_uri )
2516
+ test_frame3 = sql .read_sql_table (table , db_uri )
2517
+ query = "SELECT * FROM iris"
2518
+ test_frame4 = sql .read_sql_query (query , db_uri )
2521
2519
tm .assert_frame_equal (test_frame1 , test_frame2 )
2522
2520
tm .assert_frame_equal (test_frame1 , test_frame3 )
2523
2521
tm .assert_frame_equal (test_frame1 , test_frame4 )
@@ -2581,16 +2579,15 @@ def test_column_with_percentage(conn, request):
2581
2579
tm .assert_frame_equal (res , df )
2582
2580
2583
2581
2584
- def test_sql_open_close (test_frame3 ):
2582
+ def test_sql_open_close (temp_file , test_frame3 ):
2585
2583
# Test if the IO in the database still work if the connection closed
2586
2584
# between the writing and reading (as in many real situations).
2587
2585
2588
- with tm .ensure_clean () as name :
2589
- with contextlib .closing (sqlite3 .connect (name )) as conn :
2590
- assert sql .to_sql (test_frame3 , "test_frame3_legacy" , conn , index = False ) == 4
2586
+ with contextlib .closing (sqlite3 .connect (temp_file )) as conn :
2587
+ assert sql .to_sql (test_frame3 , "test_frame3_legacy" , conn , index = False ) == 4
2591
2588
2592
- with contextlib .closing (sqlite3 .connect (name )) as conn :
2593
- result = sql .read_sql_query ("SELECT * FROM test_frame3_legacy;" , conn )
2589
+ with contextlib .closing (sqlite3 .connect (temp_file )) as conn :
2590
+ result = sql .read_sql_query ("SELECT * FROM test_frame3_legacy;" , conn )
2594
2591
2595
2592
tm .assert_frame_equal (test_frame3 , result )
2596
2593
0 commit comments