From fc2635e00db81c678ad080b2e9ac304ae6098d17 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Wed, 31 Dec 2025 16:46:48 -0500 Subject: [PATCH] feat: fix async tests (#11176) add tests --- src/backend/tests/conftest.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/backend/tests/conftest.py b/src/backend/tests/conftest.py index 8533561ec2..a529333ee7 100644 --- a/src/backend/tests/conftest.py +++ b/src/backend/tests/conftest.py @@ -201,7 +201,10 @@ async def _delete_transactions_and_vertex_builds(session, flows: list[Flow]): @pytest.fixture async def async_client() -> AsyncGenerator: app = create_app() - async with AsyncClient(app=app, base_url="http://testserver", http2=True) as client: + async with ( + LifespanManager(app, startup_timeout=None, shutdown_timeout=None) as manager, + AsyncClient(transport=ASGITransport(app=manager.app), base_url="http://testserver", http2=True) as client, + ): yield client @@ -224,12 +227,15 @@ def session_fixture(): @pytest.fixture async def async_session(): engine = create_async_engine("sqlite+aiosqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool) - async with engine.begin() as conn: - await conn.run_sync(SQLModel.metadata.create_all) - async with AsyncSession(engine, expire_on_commit=False) as session: - yield session - async with engine.begin() as conn: - await conn.run_sync(SQLModel.metadata.drop_all) + try: + async with engine.begin() as conn: + await conn.run_sync(SQLModel.metadata.create_all) + async with AsyncSession(engine, expire_on_commit=False) as session: + yield session + async with engine.begin() as conn: + await conn.run_sync(SQLModel.metadata.drop_all) + finally: + await engine.dispose() class Config: