fix: add missing pg_conn fixture to conftest.py

Session-scoped psycopg2 fixture that skips gracefully when
POSTGRES_HOST is absent (local dev) and connects in CI. Required
by seeded_data/seeded_tracks fixtures in evolution API tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-03-18 15:19:15 -05:00
parent 4a03f98803
commit 374b82f362

View File

@ -11,6 +11,7 @@ tests.
import os
import pytest
import psycopg2
from peewee import SqliteDatabase
# Set DATABASE_TYPE=postgresql so that the module-level SKIP_TABLE_CREATION
@ -169,3 +170,39 @@ def track():
t3_threshold=448,
t4_threshold=896,
)
# ---------------------------------------------------------------------------
# PostgreSQL integration fixture (used by test_evolution_*_api.py)
# ---------------------------------------------------------------------------
@pytest.fixture(scope="session")
def pg_conn():
"""Open a psycopg2 connection to the PostgreSQL instance for integration tests.
Reads connection parameters from the standard POSTGRES_* env vars that the
CI workflow injects when a postgres service container is running. Skips the
entire session (via pytest.skip) when POSTGRES_HOST is not set, keeping
local runs clean.
The connection is shared for the whole session (scope="session") because
the integration test modules use module-scoped fixtures that rely on it;
creating a new connection per test would break those module-scoped fixtures.
Teardown: the connection is closed once all tests have finished.
"""
host = os.environ.get("POSTGRES_HOST")
if not host:
pytest.skip("POSTGRES_HOST not set — PostgreSQL integration tests skipped")
conn = psycopg2.connect(
host=host,
port=int(os.environ.get("POSTGRES_PORT", "5432")),
dbname=os.environ.get("POSTGRES_DB", "paper_dynasty"),
user=os.environ.get("POSTGRES_USER", "postgres"),
password=os.environ.get("POSTGRES_PASSWORD", ""),
)
conn.autocommit = False
yield conn
conn.close()