Fix golden-set collection when provider keys are absent
CI's `pytest --collect-only` was exiting 5 (no tests collected) because the test module used `pytest.skip(..., allow_module_level=True)` at import time — skipped modules never enter the collection phase. Switch to a per-test `skipif` marker driven by ANTHROPIC_API_KEY + COMPOSIO_API_KEY presence, and lazy-import `graph.router_node` inside the test body so module import works without COMPOSIO_API_KEY. Result: 21 tests collect in both environments; live tests run only when both keys are present. Verified locally with env -i.
This commit is contained in:
parent
3638d6ba96
commit
2bb8365972
1 changed files with 15 additions and 14 deletions
|
|
@ -1,8 +1,9 @@
|
|||
"""Golden-set routing test for the structured router.
|
||||
|
||||
20 labelled tasks → expected agent. Skipped if provider keys are missing
|
||||
(ANTHROPIC for the router LLM, COMPOSIO because importing the graph eagerly
|
||||
loads tools). Run with:
|
||||
20 labelled tasks → expected agent. Live tests require ANTHROPIC_API_KEY +
|
||||
COMPOSIO_API_KEY; without them the parametrized cases skip at runtime but
|
||||
the module still collects (so `pytest --collect-only` in CI works without
|
||||
secrets). Run with:
|
||||
|
||||
pytest tests/test_routing_golden.py -v
|
||||
"""
|
||||
|
|
@ -14,17 +15,12 @@ from dotenv import load_dotenv
|
|||
|
||||
load_dotenv(os.path.join(os.path.dirname(__file__), "..", ".env"))
|
||||
|
||||
if not os.getenv("ANTHROPIC_API_KEY"):
|
||||
pytest.skip(
|
||||
"ANTHROPIC_API_KEY not set; skipping live router tests.",
|
||||
allow_module_level=True,
|
||||
)
|
||||
if not os.getenv("COMPOSIO_API_KEY"):
|
||||
pytest.skip(
|
||||
"COMPOSIO_API_KEY not set; skipping live router tests.", allow_module_level=True
|
||||
)
|
||||
|
||||
from graph import router_node # noqa: E402
|
||||
_REQUIRED_KEYS = ("ANTHROPIC_API_KEY", "COMPOSIO_API_KEY")
|
||||
_missing = [k for k in _REQUIRED_KEYS if not os.getenv(k)]
|
||||
requires_keys = pytest.mark.skipif(
|
||||
bool(_missing),
|
||||
reason=f"Requires {', '.join(_REQUIRED_KEYS)}; missing: {', '.join(_missing)}",
|
||||
)
|
||||
|
||||
|
||||
GOLDEN_SET: list[tuple[str, str]] = [
|
||||
|
|
@ -107,8 +103,13 @@ def test_golden_set_size():
|
|||
assert len(GOLDEN_SET) == 20
|
||||
|
||||
|
||||
@requires_keys
|
||||
@pytest.mark.parametrize("task,expected", GOLDEN_SET)
|
||||
def test_router_picks_expected_agent(task: str, expected: str):
|
||||
# Lazy import — graph.py loads composio_tools at module import and needs
|
||||
# COMPOSIO_API_KEY. Keep the import inside the skipif-guarded test body.
|
||||
from graph import router_node
|
||||
|
||||
out = router_node({"task": task, "messages": []})
|
||||
assert out["route"] == expected, (
|
||||
f"task={task!r} got={out['route']} expected={expected}"
|
||||
|
|
|
|||
Reference in a new issue