From: florimondmanca Date: Sun, 12 May 2019 21:14:33 +0000 (+0200) Subject: add test for lifespan.startup.failed X-Git-Tag: 0.12.7~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F488%2Fhead;p=thirdparty%2Fstarlette.git add test for lifespan.startup.failed --- diff --git a/tests/middleware/test_lifespan.py b/tests/middleware/test_lifespan.py index 82246896..4f381c1a 100644 --- a/tests/middleware/test_lifespan.py +++ b/tests/middleware/test_lifespan.py @@ -42,11 +42,22 @@ def test_raise_on_startup(): def run_startup(): raise RuntimeError() - app = Router(routes=[Lifespan(on_startup=run_startup)]) + router = Router(routes=[Lifespan(on_startup=run_startup)]) + async def app(scope, receive, send): + async def _send(message): + nonlocal startup_failed + if message["type"] == "lifespan.startup.failed": + startup_failed = True + return await send(message) + + await router(scope, receive, _send) + + startup_failed = False with pytest.raises(RuntimeError): with TestClient(app): pass # pragma: nocover + assert startup_failed def test_raise_on_shutdown():