diff --git a/test/conftest.py b/test/conftest.py
index 0c1dff0cf6f490bbd7251d8f800e2abf98acc00f..233a0921ef67d5b1a58c14619ece9a8b1fb9c129 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -169,9 +169,9 @@ def db_uri():
database_host = os.getenv("DATABASE_HOST", "localhost")
if worker_id:
- return f"postgresql://nwa:nwa@{database_host}/gso-test-db_{worker_id}"
+ return f"postgresql+psycopg://nwa:nwa@{database_host}/gso-test-db_{worker_id}"
- return os.environ.get("DATABASE_URI_TEST", f"postgresql://nwa:nwa@{database_host}/gso-test-db")
+ return os.environ.get("DATABASE_URI_TEST", f"postgresql+psycopg://nwa:nwa@{database_host}/gso-test-db")
def run_migrations(db_uri: str) -> None:
@@ -212,15 +212,14 @@ def _database(db_uri):
engine = create_engine(url)
with engine.connect() as conn:
- conn.execute(text("COMMIT;"))
conn.execute(
text("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname=:db_name").bindparams(
db_name=db_to_create,
),
)
-
- conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
- conn.execute(text("COMMIT;"))
+ conn.commit()
+ conn.execution_options(isolation_level="AUTOCOMMIT").execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
+ conn.commit()
conn.execute(text(f'CREATE DATABASE "{db_to_create}";'))
run_migrations(db_uri)
@@ -231,12 +230,13 @@ def _database(db_uri):
finally:
db.wrapped_database.engine.dispose()
with engine.connect() as conn:
- conn.execute(text("COMMIT;"))
- # Terminate all connections to the database
conn.execute(
text(f"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='{db_to_create}';"), # noqa: S608
)
- conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
+ conn.commit()
+ conn.execution_options(isolation_level="AUTOCOMMIT").execute(
+ text(f'DROP DATABASE IF EXISTS "{db_to_create}";')
+ )
@pytest.fixture(autouse=True)