pydantic-ai/docs/api/models/test.md
Mike Pfaffenberger 256ca2d987
Name models in the docs through tiered aliases defined in docs/model_aliases/aliases.json (#10250)
Co-authored-by: David Sanchez <64162682+dsfaccini@users.noreply.github.com>
2026-10-14 20:48:29 -04:00

26 lines
852 B
Markdown

# `pydantic_ai.models.test`
Utility model for quickly testing apps built with Pydantic AI.
Here's a minimal example:
```py {title="test_model_usage.py" call_name="test_my_agent" noqa="I001"}
from pydantic_ai import Agent
from pydantic_ai.models.test import TestModel
my_agent = Agent('{{ openai:medium }}', instructions='...')
async def test_my_agent():
"""Unit test for my_agent, to be run by pytest."""
m = TestModel()
with my_agent.override(model=m):
result = await my_agent.run('Testing my agent...')
assert result.output == 'success (no tool calls)'
assert m.last_model_request_parameters is not None
assert m.last_model_request_parameters.function_tools == []
```
See [Unit testing with `TestModel`](../../testing.md#unit-testing-with-testmodel) for detailed documentation.
::: pydantic_ai.models.test