@@ -519,17 +519,20 @@ async def agen(events: list[str]) -> AsyncGenerator[int]:
519519
520520 events : list [str ] = []
521521 with RaisesGroup (
522- RaisesGroup (
523- Matcher (ValueError , match = "^agen$" ),
524- Matcher (TypeError , match = "^iterator$" ),
525- ),
526- match = r"^Encountered exception during cleanup of generator object, as well as exception in the contextmanager body - unable to unwrap.$" ,
527- ):
522+ Matcher (ValueError , match = "^agen$" ),
523+ Matcher (TypeError , match = "^iterator$" ),
524+ ) as g :
528525 async with agen (events ) as recv_chan :
529526 async for i in recv_chan : # pragma: no branch
530527 assert i == 1
531528 raise TypeError ("iterator" )
532529
530+ if sys .version_info >= (3 , 11 ):
531+ assert g .value .__notes__ == [
532+ "Encountered exception during cleanup of generator object, as "
533+ "well as exception in the contextmanager body - unable to unwrap."
534+ ]
535+
533536 assert events == ["GeneratorExit()" , "finally" ]
534537
535538
@@ -734,8 +737,12 @@ async def agen() -> AsyncGenerator[None]:
734737 while True :
735738 yield
736739
737- for _ in range (10 ): # 20% missed-alarm rate, so run ten times
738- async with agen () as chan :
739- with pytest .raises (trio .ClosedResourceError ):
740- async for _ in chan :
741- pass
740+ async with agen () as chan :
741+ with pytest .raises (trio .ClosedResourceError ):
742+ async for _ in chan :
743+ pass
744+
745+ # This is necessary to ensure that `chan` has been sent
746+ # to. Otherwise, this test sometimes passes on a broken
747+ # version of trio.
748+ await trio .testing .wait_all_tasks_blocked ()
0 commit comments