]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
add test for lifespan.startup.failed 488/head
authorflorimondmanca <florimond.manca@gmail.com>
Sun, 12 May 2019 21:14:33 +0000 (23:14 +0200)
committerflorimondmanca <florimond.manca@gmail.com>
Sun, 12 May 2019 21:14:33 +0000 (23:14 +0200)
tests/middleware/test_lifespan.py

index 8224689643472a3f822671e21f33ca215f482ae1..4f381c1af1fba22f4661402898f532c0cac6a84b 100644 (file)
@@ -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():