test_router_async_generator_lifespan() — fastapi Function Reference
Architecture documentation for the test_router_async_generator_lifespan() function in test_router_events.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 729a3368_f641_0020_269c_e7542ac3b923["test_router_async_generator_lifespan()"] 05561238_1d26_3221_b177_440da9d6e710["test_router_events.py"] 729a3368_f641_0020_269c_e7542ac3b923 -->|defined in| 05561238_1d26_3221_b177_440da9d6e710 style 729a3368_f641_0020_269c_e7542ac3b923 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_router_events.py lines 296–319
def test_router_async_generator_lifespan(state: State) -> None:
"""Test that an async generator lifespan (not wrapped) works."""
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
state.app_startup = True
yield
state.app_shutdown = True
app = FastAPI(lifespan=lifespan) # type: ignore[arg-type]
@app.get("/")
def main() -> dict[str, str]:
return {"message": "Hello World"}
assert state.app_startup is False
assert state.app_shutdown is False
with TestClient(app) as client:
assert state.app_startup is True
assert state.app_shutdown is False
response = client.get("/")
assert response.status_code == 200, response.text
assert response.json() == {"message": "Hello World"}
assert state.app_startup is True
assert state.app_shutdown is True
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_router_async_generator_lifespan() do?
test_router_async_generator_lifespan() is a function in the fastapi codebase, defined in tests/test_router_events.py.
Where is test_router_async_generator_lifespan() defined?
test_router_async_generator_lifespan() is defined in tests/test_router_events.py at line 296.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free