Use pytest fixtures, httpx.AsyncClient with ASGITransport, and app.dependency_overrides to swap DB sessions or external LLM clients cleanly. Emit structured JSON logs with request_id, user_id, route, status, and duration_ms for production debugging.
Follow-up Interview Question · How do you keep integration tests isolated when running against a real PostgreSQL instance?