From 07ea43859af71d87a60d94f2c65f46549c3c870c Mon Sep 17 00:00:00 2001
From: Matheus Polkorny <mpolkorny@gmail.com>
Date: Fri, 10 Apr 2026 13:48:23 -0300
Subject: [PATCH] Fix compatibility with Starlette 1.0

---
 tests/test_manager.py | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/tests/test_manager.py b/tests/test_manager.py
index d4e4e2e..fa7eaa6 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -40,26 +40,19 @@ async def test_lifespan_manager(
 ) -> None:
     # Setup failing event handlers.
 
-    on_startup: list = []
-    on_shutdown: list = []
-
-    if startup_exception is not None:
-
-        async def startup() -> None:
+    @contextlib.asynccontextmanager
+    async def lifespan(app):
+        if startup_exception is not None:
             assert startup_exception is not None  # Please mypy.
             raise startup_exception()
+        try:
+            yield
+        finally:
+            if shutdown_exception is not None:
+                assert shutdown_exception is not None  # Please mypy.
+                raise shutdown_exception()
 
-        on_startup.append(startup)
-
-    if shutdown_exception is not None:
-
-        async def shutdown() -> None:
-            assert shutdown_exception is not None  # Please mypy.
-            raise shutdown_exception()
-
-        on_shutdown.append(shutdown)
-
-    router = Router(on_startup=on_startup, on_shutdown=on_shutdown)
+    router = Router(lifespan=lifespan)
 
     # Set up spying on exchanged ASGI events.
 
