Python Testing
**Priority: P0 (CRITICAL)**
Universal anti-slop rules (identity fixtures, tautologies, skip/focus, mock echoing, bug-first lock, sleeps, shallow
assertions, coverage): anti-slop-rules.md. Only Python deltas
follow.
Stack Deltas
- Framework:
pytestwithpytest-asynciofor async boundaries; fixtures live inconftest.py. - Isolation (
[BE-TEST-04]): fake ormonkeypatchat external seams — DB, RPC, subprocess, Docker; patch one seam
high enough to keep the test readable; no broad monkeypatch spray.
- Parametrize (
[BE-TEST-01]):pytest.mark.parametrizefor equivalent inputs and boundaries; distinct scenarios may
stay separate.
- Assertions (
[BE-TEST-03]): assert structured outcomes — metadata, route result, blocker text, emitted command —
not shallow truthiness or implementation trivia.
- Regression (
[BE-TEST-05]): cover contract parsing, workflow routing, and verifier outcomes. - Coverage: diagnostic and project-configured; verify risk-weighted critical paths.
Recipe
- Write the failing test first for the boundary or regression.
- Patch one seam high enough to keep the test readable.
- Assert structured outcomes.
- Use async tests for async code; do not spin real event loops manually.
- Cover negative paths for malformed packets, stale runtime state, and missing env.
Anti-Patterns
- No live network or DB in unit tests: use fakes or testcontainers.
- No broad monkeypatch spray: patch the boundary, not every helper under it.
- No smoke-only proof for shared runtime changes: add focused assertions.