MCPcopy
hub / github.com/encode/starlette / test_app_async_cm_lifespan

Function test_app_async_cm_lifespan

tests/test_applications.py:390–409  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

388
389
390def 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
412deprecated_lifespan = pytest.mark.filterwarnings(

Callers

nothing calls this directly

Calls 2

StarletteClass · 0.90
test_client_factoryFunction · 0.85

Tested by

no test coverage detected