test_background_tasks_with_depends_annotated() — fastapi Function Reference
Architecture documentation for the test_background_tasks_with_depends_annotated() function in test_response_dependency.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 66a5df73_8e65_cee8_825f_1676243b9b4d["test_background_tasks_with_depends_annotated()"] b16d0181_b13b_77f6_4428_f731d5a25f66["test_response_dependency.py"] 66a5df73_8e65_cee8_825f_1676243b9b4d -->|defined in| b16d0181_b13b_77f6_4428_f731d5a25f66 style 66a5df73_8e65_cee8_825f_1676243b9b4d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_response_dependency.py lines 149–173
def test_background_tasks_with_depends_annotated():
"""BackgroundTasks type hint should work with Annotated[BackgroundTasks, Depends(...)]."""
app = FastAPI()
task_results = []
def background_task(message: str):
task_results.append(message)
def add_background_task(background_tasks: BackgroundTasks) -> BackgroundTasks:
background_tasks.add_task(background_task, "from dependency")
return background_tasks
@app.get("/")
def endpoint(
background_tasks: Annotated[BackgroundTasks, Depends(add_background_task)],
):
background_tasks.add_task(background_task, "from endpoint")
return {"status": "ok"}
client = TestClient(app)
resp = client.get("/")
assert resp.status_code == 200
assert "from dependency" in task_results
assert "from endpoint" in task_results
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_background_tasks_with_depends_annotated() do?
test_background_tasks_with_depends_annotated() is a function in the fastapi codebase, defined in tests/test_response_dependency.py.
Where is test_background_tasks_with_depends_annotated() defined?
test_background_tasks_with_depends_annotated() is defined in tests/test_response_dependency.py at line 149.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free