# Python Tests

Write regression tests for FastMCP changes using its pytest fixtures, in-memory...

- Repository: https://github.com/PrefectHQ/fastmcp (28267 stars)
- Category: Testing
- License: Apache-2.0
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add PrefectHQ/fastmcp --skill python-tests -g -a claude-code -y`
Codex: `npx skills add PrefectHQ/fastmcp --skill python-tests -g -a codex -y`
Cursor: `npx skills add PrefectHQ/fastmcp --skill python-tests -g -a cursor -y`
Gemini CLI: `npx skills add PrefectHQ/fastmcp --skill python-tests -g -a gemini-cli -y`

## Description

Write regression tests for FastMCP changes using its pytest fixtures, in-memory clients, and protocol boundaries.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# FastMCP tests

Read nearby tests, the [testing guide](../../../docs/development/tests.mdx), and the repository's validation requirements first. Extend the owning test module when it remains readable; use a focused module when the existing one is already too large.

For a bug fix, run the regression against unchanged code and confirm it fails for the reported reason, then run it with the fix. An import error or broken fixture is not a reproduced bug. To run a PR's test against main, copy it into a main worktree: `pythonpath` in pyproject shadows `PYTHONPATH`. Include supported adjacent behavior that the same branch could change, especially omitted defaults and explicit overrides.

- Async tests need no marker: `asyncio_mode = "auto"` is configured globally.
- Use `Client(server)` for real MCP dispatch without a network server. Use HTTP transport only when network behavior is the subject.
- Test the default protocol mode; pin `mode="legacy"` only when the handshake era is the subject.
- Mock external boundaries, not the FastMCP functions under test. For OpenAPI requests, capture the outgoing request with `httpx2.MockTransport` and assert its bytes, headers, or decoded parameters.
- Keep imports at module scope. Prefer function-scoped fixtures and `tmp_path` for files.
- Parameterize variations of one contract; separate unrelated behavior. For JSON, equality alone does not distinguish `True` from `1`: check the resulting type when type preservation matters.
- Use existing `inline_snapshot` conventions for complex schema assertions. Inspect generated snapshots rather than accepting them blindly.
- The default timeout is five seconds. Use the repository's integration conventions for tests that legitimately need more time.

The rest: https://github.com/PrefectHQ/fastmcp/blob/HEAD/.agents/skills/python-tests/SKILL.md
