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
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user