"""Shared pytest configuration. Puts the repository root on sys.path so tests can import the ``src`` package from any working directory, and provides ``pg_url``: a throwaway PostgreSQL schema for the database tests (stores, loaders). They need TEST_DATABASE_URL -- the variable the Rust tests use, e.g. postgres://postgres:ping@localhost:55432/ping -- and are skipped without it. """ import os import sys import uuid import pytest REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if REPO_ROOT not in sys.path: sys.path.insert(0, REPO_ROOT) @pytest.fixture def pg_url(): """Connection string whose search_path is a fresh schema, dropped after.""" base = os.environ.get("TEST_DATABASE_URL", "").strip() if not base: pytest.skip("TEST_DATABASE_URL not set (PostgreSQL test)") from sqlalchemy import create_engine, text if base.startswith("postgres://"): base = "postgresql://" + base[len("postgres://") :] schema = f"pytest_{uuid.uuid4().hex[:12]}" admin = create_engine(base) with admin.begin() as conn: conn.execute(text(f'CREATE SCHEMA "{schema}"')) sep = "&" if "?" in base else "?" try: yield f"{base}{sep}options=-csearch_path%3D{schema}" finally: with admin.begin() as conn: conn.execute(text(f'DROP SCHEMA "{schema}" CASCADE')) admin.dispose()