Run tests
Install the repository dependencies before running tests:-n 0 for a single process when debugging. The full suite uses pytest-xdist for parallel execution. To run the same marker selection as the unit CI job:
asyncio_mode = "auto" enables async tests without @pytest.mark.asyncio. These settings and the registered markers live in pyproject.toml.
Test organization and markers
Extend the module that owns the behavior, using nearby tests and fixtures as the starting point. The test tree generally mirrors the library: authentication tests are undertests/server/auth/, client tests under tests/client/, and resource tests under tests/resources/.
The pytest CI action runs
client_process and subprocess_heavy serially and excludes them from parallel unit tests. A minimal stdlib subprocess does not need subprocess_heavy merely because it is a subprocess. Use the marker when the fresh interpreter imports FastMCP.
A marker selects a CI group; it does not itself change the local timeout. To reproduce the integration group’s timeout locally:
Write a regression that proves the contract
First establish the promised behavior from the public API, docs, protocol, and relevant maintainer decisions. A reproducible result is not automatically a bug. Once the contract is clear, run the regression on the unchanged base and confirm that it fails for the intended reason, then run it with the fix. An import error or broken fixture is not evidence of the reported defect. Assert values and types that distinguish the correct result from the bug. For example, Python equality treatsTrue and 1 as equal, so a JSON type-preservation test needs a type assertion too. Avoid assertions that only check whether some result exists when the result’s contents are the contract.
Keep each test focused on one behavior, with as many assertions as that behavior needs. Parameterize variations of the same contract; separate unrelated cases. Include omitted defaults and explicit overrides when both enter the changed branch.
Use function-scoped setup and temporary paths so tests work independently and in parallel. Prefer events or waits for the exact condition being asserted to arbitrary sleeps. When diagnosing a failure, separate an assertion failure from a worker crash or infrastructure error; reproduce a supposedly pre-existing failure on the unchanged base before calling it unrelated.
Test through an in-memory client
Client(server) exercises real FastMCP dispatch and protocol behavior without opening a socket. This complete test checks how arguments and results travel through the client:
uv run pytest path/to/test_example.py -n 0. Use the existing fixture patterns for the subsystem instead of mocking the FastMCP method under test.
Failure behavior
Assert the exception users receive, including a meaningful message when that is part of the behavior:Reusable fixtures
Build the server in a fixture and manage the client context in the test. This keeps connection ownership and cleanup visible:Schema snapshots
Use the repository’sinline-snapshot conventions for complex structures. Inspect each generated expectation against the contract before accepting it. This example checks the schema returned through the protocol:
--inline-snapshot=fix and review the diff. Use --inline-snapshot=create when populating a new empty snapshot.
Test HTTP behavior without a socket
Useasgi_client when the subject is HTTP routing, headers, authentication, or streaming. It builds the real application and starts its lifespan, then sends requests directly through ASGI in the same process:
headers= or auth= to configure requests, path= for a custom MCP route, or transport="sse" to exercise the SSE application. Other client options, such as timeout=, go to Client.
Multiple clients and raw requests
Useasgi_server when a test needs several clients or raw HTTP responses. Each client() call creates its own client. http_client() returns an httpx2.AsyncClient bound to the same application; an ordinary network client cannot reach this in-process server.
ping should pass mode="legacy" to the client. The modern protocol era is sessionless; see protocol negotiation. For custom client transports, running.transport() returns a transport wired to the same application.
Test external and process boundaries
Mock external services at their boundary, while keeping the FastMCP path real. For outgoing HTTP requests, usehttpx2.MockTransport and assert the method, URL, headers, or body that matter. Do not mock the framework function whose behavior the test is meant to verify.
Use run_server_async when the network itself is the subject: a socket, TLS, or a client outside the in-process application. It starts uvicorn in the current process and cleans it up on exit:
run_server_in_process only when process isolation is part of the test. Follow nearby subprocess fixtures for startup, transport selection, and cleanup. Stdio lifecycle tests can use tests/client/minimal_stdio_server.py when a minimal MCP responder suffices; use a real FastMCP subprocess when its behavior is what you need to test.
Check documentation examples
Run the documentation checks from the repository root:just docs to preview rendering. Without just, run npx --yes mint@latest broken-links or npx --yes mint@latest dev from docs/.
See the Contributing Guide for the full checks required before committing.
