MCPcopy Index your code
hub / github.com/fastapi/fastapi / test_response_with_depends_default

Function test_response_with_depends_default

tests/test_response_dependency.py:34–51  ·  view source on GitHub ↗

Response type hint should work with Response = Depends(...).

()

Source from the content-addressed store, hash-verified

32
33
34def test_response_with_depends_default():
35 """Response type hint should work with Response = Depends(...)."""
36 app = FastAPI()
37
38 def modify_response(response: Response) -> Response:
39 response.headers["X-Custom"] = "modified"
40 return response
41
42 @app.get("/")
43 def endpoint(response: Response = Depends(modify_response)):
44 return {"status": "ok"}
45
46 client = TestClient(app)
47 resp = client.get("/")
48
49 assert resp.status_code == 200
50 assert resp.json() == {"status": "ok"}
51 assert resp.headers.get("X-Custom") == "modified"
52
53
54def test_response_without_depends():

Callers

nothing calls this directly

Calls 2

FastAPIClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…