Performance: TestClient basics
MEDIUM IMPACT
This affects the speed and efficiency of backend API testing, impacting developer feedback loop and CI pipeline speed.
from fastapi.testclient import TestClient from myapp import app client = TestClient(app) response = client.get('/items/1') assert response.status_code == 200
import requests response = requests.get('http://localhost:8000/items/1') assert response.status_code == 200
| Pattern | Network Calls | Server Dependency | Test Speed | Verdict |
|---|---|---|---|---|
| Real HTTP requests with requests library | Yes | Requires running server | Slow due to network latency | [X] Bad |
| In-memory requests with FastAPI TestClient | No | No server needed | Fast, immediate response | [OK] Good |