move await engine.dispose() to test client

This commit is contained in:
kuba 2022-02-02 13:54:41 +01:00
parent bec67cf98b
commit 14eef23f85
3 changed files with 5 additions and 3 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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")