From 374b82f362abf26308022b50e9ba01710db3a4b1 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 18 Mar 2026 15:19:15 -0500 Subject: [PATCH] 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) --- tests/conftest.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 503da01..3127355 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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()