@@ -885,24 +885,32 @@ async def started_sleeper(task_status: _core.TaskStatus[None]) -> None:
885
885
async def unstarted_task () -> None :
886
886
raise AssertionError ("this should not even get a chance to run" )
887
887
888
- async with AsyncExitStack () as stack :
889
- manager = _core .open_nursery ()
890
- nursery = await manager .__aenter__ ()
891
- # The asynccontextmanager is going to create a nursery that outlives this nursery!
892
- nursery .start_soon (
893
- stack .enter_async_context ,
894
- asynccontextmanager_that_creates_a_nursery_internally (),
895
- )
896
- with pytest .RaisesGroup (
888
+ with pytest .RaisesGroup (
889
+ pytest .RaisesExc (
890
+ RuntimeError ,
891
+ match = "Task .*unstarted_task.* aborted after nursery was destroyed due to misnesting." ,
892
+ ),
893
+ pytest .RaisesExc (
894
+ RuntimeError ,
895
+ match = "Task .*started_sleeper.* aborted after nursery was destroyed due to misnesting." ,
896
+ ),
897
+ pytest .RaisesGroup (
897
898
pytest .RaisesExc (RuntimeError , match = "Nursery stack corrupted" )
898
- ):
899
- await manager .__aexit__ (None , None , None )
899
+ ),
900
+ ):
901
+ async with AsyncExitStack () as stack , _core .open_nursery () as nursery :
902
+ # The asynccontextmanager is going to create a nursery that outlives this nursery!
903
+ nursery .start_soon (
904
+ stack .enter_async_context ,
905
+ asynccontextmanager_that_creates_a_nursery_internally (),
906
+ )
900
907
901
908
# The outer nursery forcefully aborts the inner nursery and stops `unstarted_task`
902
909
# from ever being started.
910
+ # `started_sleeper` is awaited, but not the internal `sleep`
903
911
with pytest .warns (
904
912
RuntimeWarning ,
905
- match = "^coroutine 'test_asyncexitstack_nursery_misnest.<locals>.unstarted_task' was never awaited$" ,
913
+ match = "^coroutine '( test_asyncexitstack_nursery_misnest.<locals>.unstarted_task|sleep) ' was never awaited$" ,
906
914
):
907
915
gc_collect_harder ()
908
916
0 commit comments