A practical guide to designing Pytest strategies for agent-generated code, covering how to structure test-writing sub-agents with constrained roles, define explicit testing levels (with business logic tests over fakes as the majority), and enforce anti-patterns to prevent performance erosion and brittleness. Key principles include using fake infrastructure instead of mocks, scoping agents to current work only, separating feature vs. bug-fix workflows, and defining both micro- and macro-level constraints. A real pull request example illustrates how these rules produce fast, deterministic, refactor-resilient tests.
Table of contents
How to Run Agentic TestsWhen Agents Write TestsChoosing the Right Test LevelPreventing Anti-PatternsPutting the Strategy into PracticeWhy a Testing Strategy is Still Foundational1 Impression