fastapi-testing
FastAPI integration testing specialist. Covers synchronous TestClient, async httpx AsyncClient, dependency injection overrides, auth testing (JWT, OAuth2, API keys), WebSocket testing, file uploads, background tasks, middleware testing, and HTTP mocking with respx, responses, and pytest-httpserver. USE WHEN: user mentions "FastAPI test", "TestClient", "httpx async test", "dependency override test", "respx mock", asks about testing FastAPI endpoints, authentication in tests, or HTTP client mocking. DO NOT USE FOR: Django - use `pytest-django`; pytest internals - use `pytest`; Container infrastructure - use `testcontainers-python`
What this skill does
# FastAPI Testing
> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `fastapi-testing`
> for comprehensive documentation on TestClient, async testing, auth, and HTTP mocking.
## Synchronous TestClient
```python
from fastapi.testclient import TestClient
from myapp.main import app
client = TestClient(app)
def test_read_root():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}
def test_post_item():
response = client.post(
"/items/",
json={"name": "Widget", "price": 9.99},
)
assert response.status_code == 201
```
## Lifespan Events
```python
def test_with_lifespan():
with TestClient(app) as client: # triggers startup/shutdown
response = client.get("/items/")
assert response.status_code == 200
```
## Async TestClient (httpx)
```python
import pytest
from httpx import ASGITransport, AsyncClient
from myapp.main import app
@pytest.mark.anyio
async def test_async():
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://test"
) as ac:
response = await ac.get("/")
assert response.status_code == 200
# Shared fixture
@pytest.fixture(scope="module")
async def async_client():
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://test"
) as client:
yield client
```
## Dependency Overrides
```python
# Production dependency
async def get_db() -> AsyncSession:
async with AsyncSessionLocal() as session:
yield session
# Test: override with test session
@pytest.fixture
def client(db_session):
def override_get_db():
yield db_session
app.dependency_overrides[get_db] = override_get_db
with TestClient(app) as c:
yield c
app.dependency_overrides.clear()
# Override user authentication
async def override_current_user():
return User(id=1, username="testuser", is_active=True)
app.dependency_overrides[get_current_user] = override_current_user
```
## Auth Testing — JWT
```python
from datetime import timedelta
from myapp.auth import create_access_token
def get_test_token(username="testuser") -> str:
return create_access_token(
data={"sub": username},
expires_delta=timedelta(minutes=30),
)
def test_protected_endpoint():
token = get_test_token()
response = client.get(
"/users/me/",
headers={"Authorization": f"Bearer {token}"},
)
assert response.status_code == 200
def test_no_token():
response = client.get("/users/me/")
assert response.status_code == 401
```
## WebSocket Testing
```python
def test_websocket():
with client.websocket_connect("/ws") as ws:
ws.send_text("hello")
data = ws.receive_text()
assert data == "Echo: hello"
```
## File Upload Testing
```python
def test_upload_file():
response = client.post(
"/uploadfile/",
files={"file": ("test.txt", b"hello world", "text/plain")},
)
assert response.status_code == 200
assert response.json() == {"filename": "test.txt", "size": 11}
```
## Background Tasks Testing
```python
from unittest.mock import patch
def test_task_called():
with patch("fastapi.BackgroundTasks.add_task") as mock:
response = client.post("/send-notification/[email protected]")
assert response.status_code == 200
mock.assert_called_once()
```
## HTTP Mocking — respx
```python
import httpx
import respx
@respx.mock
def test_external_api():
respx.get("https://api.example.com/users").mock(
return_value=httpx.Response(200, json=[{"id": 1, "name": "Alice"}])
)
response = client.get("/proxy/users")
assert response.status_code == 200
# With side effects
@respx.mock
async def test_async_mock():
respx.post("https://api.example.com/data").mock(
side_effect=httpx.ConnectError
)
with pytest.raises(httpx.ConnectError):
async with httpx.AsyncClient() as ac:
await ac.post("https://api.example.com/data")
```
## HTTP Mocking — responses (requests library)
```python
import responses
import requests
@responses.activate
def test_with_responses():
responses.get(
"https://api.example.com/users",
json=[{"id": 1}],
status=200,
)
result = my_service.get_users()
assert len(result) == 1
```
## HTTP Mocking — pytest-httpserver
```python
def test_real_server(httpserver):
httpserver.expect_request("/data").respond_with_json({"key": "value"})
response = requests.get(httpserver.url_for("/data"))
assert response.json() == {"key": "value"}
```
## Anti-Patterns
| Anti-Pattern | Solution |
|---|---|
| `app.dependency_overrides` not cleared | Use `yield` + `app.dependency_overrides.clear()` in fixture |
| Creating `TestClient` per test | Module or session scope `TestClient` |
| Testing with real external APIs | Use respx/responses to mock |
| Not using `ASGITransport` for async | Required for httpx with ASGI apps |
**Official docs:** https://fastapi.tiangolo.com/tutorial/testing/
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.