github-actions[bot]
Automated Deploy: f4f01388c7b26e818cffbd64414eac11381a7891
35e80ff
Raw History Blame Contribute Delete
1.76 kB
"""Fixtures: settings that never touch the network or the real cache."""
from __future__ import annotations
import logging
import pytest
from ai_coach.config import Settings
from ai_coach.input_builder import build_coach_input
from ai_coach.schemas import CoachInput
from .helpers import example_names, load_example
@pytest.fixture(autouse=True)
def isolate_coach_logging():
"""Entry-point tests must not leave their file handlers or propagation policy behind."""
logger = logging.getLogger("ai_coach")
handlers = list(logger.handlers)
level, propagate, disabled = logger.level, logger.propagate, logger.disabled
try:
yield
finally:
for handler in list(logger.handlers):
if handler not in handlers:
logger.removeHandler(handler)
handler.close()
for handler in handlers:
if handler not in logger.handlers:
logger.addHandler(handler)
logger.setLevel(level)
logger.propagate, logger.disabled = propagate, disabled
@pytest.fixture
def settings(tmp_path) -> Settings:
"""LLM disabled by default; tests that need it pass a key explicitly."""
return Settings(_env_file=None, google_api_key=None, cache_path=tmp_path / "cache.sqlite3", daily_budget_usd=1.0)
@pytest.fixture
def keyed_settings(tmp_path) -> Settings:
return Settings(
_env_file=None,
google_api_key="test-key-123",
cache_path=tmp_path / "cache.sqlite3",
model="gemini-3.1-flash-lite",
escalation_model="gemini-3.8-flash",
daily_budget_usd=1.0,
)
@pytest.fixture
def real_inputs() -> dict[str, CoachInput]:
return {name: build_coach_input(load_example(name)) for name in example_names()}