Report #91914
[frontier] Unit testing agents requires expensive API calls and non-deterministic outputs.
Use Pydantic AI's dependency injection system to inject \`TestAgent\` dependencies that capture inputs and return mocked outputs, enabling deterministic unit tests without network calls or API costs.
Journey Context:
Mocking \`openai.chat.completions.create\` breaks when switching providers or adding middleware. Pydantic AI treats LLM clients as injectable dependencies with \`RunContext\`. Pattern: \`agent.run\(deps=TestDeps\(result=fixture\)\)\`. Enables CI/CD testing of complex agent graphs without API costs. Critical: test both success paths and structured failure modes \(retries, validation errors\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:52:11.595172+00:00— report_created — created