"""Fixtures for the backend suite. The backend runs *from* `backend/` and has no __init__.py anywhere, so its modules are top-level imports (`import inbox_classifier.prompt`). pytest is invoked from the repo root, so `backend/` has to go on sys.path here — the root suite (tests/) imports the installed `app` package instead and needs no such help. No live API calls anywhere: the adapter is exercised against a fake `responses` resource, exactly as tests/unit/test_llm.py does. """ from __future__ import annotations import os import sys from collections.abc import Iterator from pathlib import Path import pytest _BACKEND = Path(__file__).resolve().parent.parent if str(_BACKEND) not in sys.path: # APPEND, never insert(0): backend/ contains a `tests` directory of its own, so # putting it first would shadow the root `tests` package and break the root # suite's `from tests.conftest import ...` imports. sys.path.append(str(_BACKEND)) @pytest.fixture(autouse=True) def _hermetic_env(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]: """Keep the suite hermetic. A real key must never leak in from the environment, and a developer's local OPENAI_MODEL or INBOX_TRIAGE_* values must not change what the tests assert. """ for name in list(os.environ): upper = name.upper() if upper.startswith(("OPENAI_", "ANTHROPIC_", "INBOX_TRIAGE_", "SCORING_", "MAX_")): monkeypatch.delenv(name, raising=False) yield