fastapi.testclient.TestClient (built on httpx) calls the app in-process — no server, no network. Combine it with pytest fixtures and dependency overrides. Task How Sync tests TestClient(app) Startup/shutdown (lifespan) with TestClient(app) as client: Async tests httpx.AsyncClient(transport=ASGITransport(app)) + pytest-asyncio / anyio Replace DB/auth app.dependencyoverrides[dep] = fake WebSockets client.websocketconnect("/ws") Run: pytest -q.