(test_client_factory: TestClientFactory)
| 388 | |
| 389 | |
| 390 | def test_app_async_cm_lifespan(test_client_factory: TestClientFactory) -> None: |
| 391 | startup_complete = False |
| 392 | cleanup_complete = False |
| 393 | |
| 394 | @asynccontextmanager |
| 395 | async def lifespan(app: ASGIApp) -> AsyncGenerator[None, None]: |
| 396 | nonlocal startup_complete, cleanup_complete |
| 397 | startup_complete = True |
| 398 | yield |
| 399 | cleanup_complete = True |
| 400 | |
| 401 | app = Starlette(lifespan=lifespan) |
| 402 | |
| 403 | assert not startup_complete |
| 404 | assert not cleanup_complete |
| 405 | with test_client_factory(app): |
| 406 | assert startup_complete |
| 407 | assert not cleanup_complete |
| 408 | assert startup_complete |
| 409 | assert cleanup_complete |
| 410 | |
| 411 | |
| 412 | deprecated_lifespan = pytest.mark.filterwarnings( |
nothing calls this directly
no test coverage detected