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 <noreply@anthropic.com>
This commit is contained in:
1 parent
adf8a9b290
commit
f761c27d1a
3 files changed
+50
-1
No files matched your search
@@ -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
|
||||
|
||||
+2
-1
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user