python-tests
GitHub提供FastMCP项目的回归测试编写指南,涵盖pytest fixtures、内存客户端使用及协议边界验证。指导如何正确复现bug、模拟外部依赖、处理异步测试及快照断言,确保代码质量与兼容性。
触发场景
安装
npx skills add PrefectHQ/fastmcp --skill python-tests -g -y
SKILL.md
Frontmatter
{
"name": "python-tests",
"description": "Write regression tests for FastMCP changes using its pytest fixtures, in-memory clients, and protocol boundaries."
}
FastMCP tests
Read nearby tests, the testing guide, 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.MockTransportand assert its bytes, headers, or decoded parameters. - Keep imports at module scope. Prefer function-scoped fixtures and
tmp_pathfor files. - Parameterize variations of one contract; separate unrelated behavior. For JSON, equality alone does not distinguish
Truefrom1: check the resulting type when type preservation matters. - Use existing
inline_snapshotconventions 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.
Run focused tests during development, then the full commands required by AGENTS.md before committing. If a failure appears unrelated, reproduce it on the unchanged base; do not call it pre-existing from the test name alone.
版本历史
-
623590a
当前 2026-10-20 04:43
新增关于全局异步模式配置、默认超时时间以及文档引用路径的说明;明确禁止将导入错误或fixture损坏视为已复现的Bug。
- c6165d9 2026-09-23 08:38


