Skip to content

Commit 9400eb9

Browse files
seidnerjpgjones
authored andcommitted
fix test_startup_failure test to support ExceptionGroup exceptions
1 parent 1cd0030 commit 9400eb9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/trio/test_lifespan.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from __future__ import annotations
2+
import sys
3+
4+
if sys.version_info < (3, 11):
5+
from exceptiongroup import ExceptionGroup
26

37
import pytest
48
import trio
@@ -24,9 +28,17 @@ async def test_startup_timeout_error(nursery: trio._core._run.Nursery) -> None:
2428
@pytest.mark.trio
2529
async def test_startup_failure() -> None:
2630
lifespan = Lifespan(ASGIWrapper(lifespan_failure), Config())
31+
2732
with pytest.raises(LifespanFailureError) as exc_info:
28-
async with trio.open_nursery() as lifespan_nursery:
29-
await lifespan_nursery.start(lifespan.handle_lifespan)
30-
await lifespan.wait_for_startup()
33+
try:
34+
async with trio.open_nursery() as lifespan_nursery:
35+
await lifespan_nursery.start(lifespan.handle_lifespan)
36+
await lifespan.wait_for_startup()
37+
except ExceptionGroup as exception:
38+
target_exception = exception
39+
if len(exception.exceptions) == 1:
40+
target_exception = exception.exceptions[0]
41+
42+
raise target_exception.with_traceback(target_exception.__traceback__)
3143

3244
assert str(exc_info.value) == "Lifespan failure in startup. 'Failure'"

0 commit comments

Comments
 (0)