MCPcopy
hub / github.com/encode/uvicorn / test_lifespan_state

Function test_lifespan_state

tests/test_lifespan.py:244–264  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

242
243
244def test_lifespan_state():
245 async def app(scope, receive, send):
246 message = await receive()
247 assert message["type"] == "lifespan.startup"
248 await send({"type": "lifespan.startup.complete"})
249 scope["state"]["foo"] = 123
250 message = await receive()
251 assert message["type"] == "lifespan.shutdown"
252 await send({"type": "lifespan.shutdown.complete"})
253
254 async def test():
255 config = Config(app=app, lifespan="on")
256 lifespan = LifespanOn(config)
257
258 await lifespan.startup()
259 assert lifespan.state == {"foo": 123}
260 await lifespan.shutdown()
261
262 loop = asyncio.new_event_loop()
263 loop.run_until_complete(test())
264 loop.close()

Callers

nothing calls this directly

Calls 2

testFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected