From 11dadb4d45161d183aa091115f4f798b0990872d Mon Sep 17 00:00:00 2001 From: Adrien Berchet Date: Wed, 1 May 2024 20:12:15 +0200 Subject: [PATCH] Test: Dispose of the connection pools of the test engines (#511) --- tests/conftest.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index bae2929c..e4a4813e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -161,18 +161,23 @@ def engine(tmpdir, db_url, _engine_echo): # Copy the input SQLite DB to a temporary file and return an engine to it input_url = str(db_url)[10:] output_file = "test_spatial_db.sqlite" - return copy_and_connect_sqlite_db(input_url, tmpdir / output_file, _engine_echo, "sqlite") - - if db_url.startswith("gpkg:///"): + current_engine = copy_and_connect_sqlite_db( + input_url, tmpdir / output_file, _engine_echo, "sqlite" + ) + elif db_url.startswith("gpkg:///"): # Copy the input SQLite DB to a temporary file and return an engine to it input_url = str(db_url)[8:] output_file = "test_spatial_db.gpkg" - return copy_and_connect_sqlite_db(input_url, tmpdir / output_file, _engine_echo, "gpkg") + current_engine = copy_and_connect_sqlite_db( + input_url, tmpdir / output_file, _engine_echo, "gpkg" + ) + else: + # For other dialects the engine is directly returned + current_engine = create_engine(db_url, echo=_engine_echo) + current_engine.update_execution_options(search_path=["gis", "public"]) - # For other dialects the engine is directly returned - engine = create_engine(db_url, echo=_engine_echo) - engine.update_execution_options(search_path=["gis", "public"]) - return engine + yield current_engine + current_engine.dispose() @pytest.fixture