Files
Metamorph/backend/tests/conftest.py

26 lines
781 B
Python
Raw Normal View History

2026-05-11 06:05:27 +02:00
"""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