MCPcopy
hub / github.com/fastapi/fastapi / test_response_with_depends_annotated

Function test_response_with_depends_annotated

tests/test_response_dependency.py:14–31  ·  view source on GitHub ↗

Response type hint should work with Annotated[Response, Depends(...)].

()

Source from the content-addressed store, hash-verified

12
13
14def test_response_with_depends_annotated():
15 """Response type hint should work with Annotated[Response, Depends(...)]."""
16 app = FastAPI()
17
18 def modify_response(response: Response) -> Response:
19 response.headers["X-Custom"] = "modified"
20 return response
21
22 @app.get("/")
23 def endpoint(response: Annotated[Response, Depends(modify_response)]):
24 return {"status": "ok"}
25
26 client = TestClient(app)
27 resp = client.get("/")
28
29 assert resp.status_code == 200
30 assert resp.json() == {"status": "ok"}
31 assert resp.headers.get("X-Custom") == "modified"
32
33
34def test_response_with_depends_default():

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…