"""Keep summarizer unit tests importable without Postgres drivers, offline.""" from __future__ import annotations import sys from pathlib import Path from types import ModuleType _SUMMERIZER_DIR = Path(__file__).resolve().parent.parent if str(_SUMMERIZER_DIR) not in sys.path: sys.path.insert(0, str(_SUMMERIZER_DIR)) if "psycopg2" not in sys.modules: fake = ModuleType("psycopg2") fake.connect = lambda **kwargs: None # type: ignore[attr-defined] sys.modules["psycopg2"] = fake import pytest # noqa: E402 @pytest.fixture(autouse=True) def offline_llm_defaults(monkeypatch): """No network and no retry sleeps unless a test asks for them. ``summarize_news()`` validates SUMMARY_MODEL against ``GET /models`` once per process; unit tests must never leave the box for it. Tests that exercise the missing-model path patch ``summarizer.model_available`` themselves (a later ``setattr`` wins over this one). """ import nous_client import summarizer monkeypatch.setenv("NOUS_RETRY_BACKOFF_S", "0") nous_client.reset_model_cache() monkeypatch.setattr(summarizer, "model_available", lambda **kwargs: True) yield nous_client.reset_model_cache()