From 05b8bc3e7ea7fe0999b6391995d3edc16b2b5197 Mon Sep 17 00:00:00 2001 From: Lacky1234union Date: Sun, 4 Oct 2026 15:06:16 +0300 Subject: [PATCH] test: never call a live LLM from tests, whatever the local .env says With OPENROUTER_API_KEY in a developer's .env the chat agent switched on in dialog tests (real API calls, spent money, flaky results). An autouse fixture turns the agent off; agent tests pass explicit providers. Co-Authored-By: Claude Opus 5.5 --- tests/conftest.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..2bf9991 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +"""Test-wide isolation: a developer's local `.env` (e.g. OPENROUTER_API_KEY) must never make tests call a real +LLM provider — that costs money and makes results depend on the network. Agent tests pass explicit +providers/settings; everything else runs with the chat agent off.""" + +import pytest + +from app.config import get_settings + + +@pytest.fixture(autouse=True) +def _no_live_llm(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("CHAT_AGENT", "off") + monkeypatch.setenv("OPENROUTER_API_KEY", "") + monkeypatch.setenv("LLM_PROVIDER", "mock") + get_settings.cache_clear() + yield + get_settings.cache_clear()