test_response_dependency_returns_different_response_instance() — fastapi Function Reference
Architecture documentation for the test_response_dependency_returns_different_response_instance() function in test_response_dependency.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD a7db760f_3c57_1713_3b1e_18fecc0eb84a["test_response_dependency_returns_different_response_instance()"] b16d0181_b13b_77f6_4428_f731d5a25f66["test_response_dependency.py"] a7db760f_3c57_1713_3b1e_18fecc0eb84a -->|defined in| b16d0181_b13b_77f6_4428_f731d5a25f66 style a7db760f_3c57_1713_3b1e_18fecc0eb84a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_response_dependency.py lines 97–121
def test_response_dependency_returns_different_response_instance():
"""Dependency that returns a different Response instance should work.
When a dependency returns a new Response object (e.g., JSONResponse) instead
of modifying the injected one, the returned response should be used and any
modifications to it in the endpoint should be preserved.
"""
app = FastAPI()
def default_response() -> Response:
response = JSONResponse(content={"status": "ok"})
response.headers["X-Custom"] = "initial"
return response
@app.get("/")
def endpoint(response: Annotated[Response, Depends(default_response)]):
response.headers["X-Custom"] = "modified"
return response
client = TestClient(app)
resp = client.get("/")
assert resp.status_code == 200
assert resp.json() == {"status": "ok"}
assert resp.headers.get("X-Custom") == "modified"
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_response_dependency_returns_different_response_instance() do?
test_response_dependency_returns_different_response_instance() is a function in the fastapi codebase, defined in tests/test_response_dependency.py.
Where is test_response_dependency_returns_different_response_instance() defined?
test_response_dependency_returns_different_response_instance() is defined in tests/test_response_dependency.py at line 97.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free