diff --git a/tests/conftest.py b/tests/conftest.py index 23a0dd1..36e3ede 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -32,3 +32,6 @@ async def client() -> AsyncClient: ) as client: await start_db() yield client + # for AsyncEngine created in function scope, close and + # clean-up pooled connections + await engine.dispose() diff --git a/the_app/database.py b/the_app/database.py index 05e9487..0652a5b 100644 --- a/the_app/database.py +++ b/the_app/database.py @@ -31,6 +31,4 @@ async def get_db() -> AsyncGenerator: raise ex finally: await session.close() - # for AsyncEngine created in function scope, close and - # clean-up pooled connections - await engine.dispose() + diff --git a/the_app/main.py b/the_app/main.py index 2d4faa8..6d69815 100644 --- a/the_app/main.py +++ b/the_app/main.py @@ -17,6 +17,7 @@ app.include_router(nonsense_router) async def start_db(): async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) + await engine.dispose() @app.on_event("startup")