From f761c27d1a9685caeb3d939b75c6479e9a9823dd Mon Sep 17 00:00:00 2001 From: Torben Nehmer Date: Fri, 4 Dec 2026 06:44:44 +0100 Subject: [PATCH] Add live test behind the live marker Plain pytest deselects it; -m live runs it and skips without a key. Co-Authored-By: Claude Sonnet 5.5 --- CLAUDE.md | 1 + pyproject.toml | 3 ++- tests/adapters/test_llm_live.py | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/adapters/test_llm_live.py diff --git a/CLAUDE.md b/CLAUDE.md index a582cfe..a0d02da 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -20,6 +20,7 @@ Importe zeigen nach innen: application → ports → domain; adapters → ports, ``` uv sync --locked # Umgebung aus dem Lock uv run pytest +uv run pytest -m live # Live-Test; Key in CHEMENU_ANTHROPIC_API_KEY, nur in der eigenen Shell uv run ruff check # und: uv run ruff format uv run lint-imports # Schichtregel (Importrichtung) prüfen uv run pyright diff --git a/pyproject.toml b/pyproject.toml index 1c80a5b..c12f88b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,8 @@ venv = ".venv" [tool.pytest.ini_options] minversion = "9.0" testpaths = ["tests"] -addopts = ["-ra", "--strict-markers", "--strict-config"] +addopts = ["-ra", "--strict-markers", "--strict-config", "-m", "not live"] +markers = ["live: calls a paid provider API; run with -m live"] xfail_strict = true [tool.importlinter] diff --git a/tests/adapters/test_llm_live.py b/tests/adapters/test_llm_live.py new file mode 100644 index 0000000..1c7d627 --- /dev/null +++ b/tests/adapters/test_llm_live.py @@ -0,0 +1,47 @@ +import os + +import pytest +from pydantic import BaseModel + +from chemenu.adapters.llm.config import LlmConfig +from chemenu.adapters.llm.factory import build_llm +from chemenu.domain.step_profile import StepProfile +from chemenu.ports.llm import LlmRequest + +_KEY_ENV = "CHEMENU_ANTHROPIC_API_KEY" +_MODEL = "claude-haiku-5-5" + + +class _Answer(BaseModel): + answer: int + + +@pytest.mark.live +def test_live_anthropic_call() -> None: + if not os.environ.get(_KEY_ENV): + pytest.skip(f"{_KEY_ENV} not set; the live test calls a paid API") + config = LlmConfig.model_validate( + { + "providers": {"anthropic": {"kind": "anthropic", "api_key_env": _KEY_ENV}}, + "profiles": { + "classify": { + "provider": "anthropic", + "model": _MODEL, + "effort": "low", + "max_tokens": 2000, + "timeout_seconds": 120, + } + }, + } + ) + port = build_llm(config, os.environ) + request = LlmRequest( + step="live-check", + profile=StepProfile.CLASSIFY, + prompt="Wie viel ist 2+3?", + output_model=_Answer, + ) + response = port.complete(request) + assert response.model == _MODEL + assert response.usage.input_tokens > 0 + _Answer.model_validate_json(response.text, strict=True)