Milestone 3
This commit is contained in:
25
backend/tests/conftest.py
Normal file
25
backend/tests/conftest.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Shared pytest fixtures.
|
||||
|
||||
The DB integration tests need a reachable Postgres on the URL configured in
|
||||
`app.core.config.settings`. They are skipped automatically when the DB isn't up,
|
||||
so unit tests still pass on a developer's bare laptop.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.exc import OperationalError
|
||||
|
||||
from app.db.session import get_engine
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def db_engine_or_skip():
|
||||
"""Yield the SQLAlchemy engine, skipping the test if the DB is unreachable."""
|
||||
engine = get_engine()
|
||||
try:
|
||||
with engine.connect() as conn:
|
||||
conn.execute.__self__ # touch the connection
|
||||
except OperationalError as e:
|
||||
pytest.skip(f"Postgres unreachable: {e}", allow_module_level=False)
|
||||
return engine
|
||||
Reference in New Issue
Block a user