From 477abad4c98acdfaf3b63c3f44b5e14c09dc6ab9 Mon Sep 17 00:00:00 2001 From: Fusion Date: Thu, 14 May 2026 08:45:41 +0200 Subject: [PATCH] fix(FN-011): gracefully skip DB tests when PostgreSQL is unavailable - Wrap DB engine setup in try/except in conftest.py - Call pytest.skip with clear message when PostgreSQL is unavailable - Dispose engine before skipping to avoid connection leaks Fusion-Task-Id: FN-011 --- apps/api/tests/conftest.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/api/tests/conftest.py b/apps/api/tests/conftest.py index 9a2af3a..5c79ed0 100644 --- a/apps/api/tests/conftest.py +++ b/apps/api/tests/conftest.py @@ -34,8 +34,12 @@ def event_loop() -> Generator[Any, None, None]: @pytest.fixture(scope="session") async def db_engine() -> AsyncGenerator[AsyncEngine, None]: engine = create_async_engine(TEST_DATABASE_URL, echo=False, poolclass=NullPool) - async with engine.begin() as conn: - await conn.run_sync(Base.metadata.create_all) + try: + async with engine.begin() as conn: + await conn.run_sync(Base.metadata.create_all) + except Exception as exc: + await engine.dispose() + pytest.skip(f"PostgreSQL unavailable for tests: {exc}") yield engine async with engine.begin() as conn: await conn.run_sync(Base.metadata.drop_all)