From: Bastian Germann Date: Fri, 8 May 2026 12:38:34 +0200 Subject: Fix test failures on modern trio and Python 3.13 - Unwrap single-exception ExceptionGroups in TrioBackend.Background.__aexit__ so errors propagate consistently with the asyncio backend; trio wraps all nursery exceptions (even lone ones) in an ExceptionGroup since v0.22. - Extend the xfail raises= marker for trio's http_no_assert_before_receive_request variant to accept ExceptionGroup in addition to AssertionError, because pytest-trio surfaces the uncaught assertion inside a nursery ExceptionGroup. --- src/asgi_lifespan/_concurrency/trio.py | 10 +++++++++- tests/test_manager.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/asgi_lifespan/_concurrency/trio.py b/src/asgi_lifespan/_concurrency/trio.py index 93716c9..7ac875a 100644 --- a/src/asgi_lifespan/_concurrency/trio.py +++ b/src/asgi_lifespan/_concurrency/trio.py @@ -69,4 +69,12 @@ class Background: exc_value: typing.Optional[BaseException] = None, traceback: typing.Optional[types.TracebackType] = None, ) -> None: - await self._exit_stack.__aexit__(exc_type, exc_value, traceback) + try: + await self._exit_stack.__aexit__(exc_type, exc_value, traceback) + except BaseException as exc: + # Trio wraps nursery exceptions in ExceptionGroup (even single ones). + # Unwrap single-exception groups to give consistent behaviour with asyncio. + exceptions = getattr(exc, "exceptions", None) + if exceptions is not None and len(exceptions) == 1: + raise exceptions[0] + raise diff --git a/tests/test_manager.py b/tests/test_manager.py index fa7eaa6..d7700c9 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -208,7 +208,7 @@ async def http_no_assert_before_receive_request( http_no_assert_before_receive_request, marks=pytest.mark.xfail( reason="No way for us to detect unsupported lifespan in this case.", - raises=AssertionError, + raises=(AssertionError, ExceptionGroup), ), ), ],