@@ -641,7 +641,6 @@ def __eq__(self, other: object) -> bool:
641641
642642@_core .enable_ki_protection
643643async def _protected_async_gen_fn () -> AsyncGenerator [None , None ]:
644- return
645644 yield
646645
647646
@@ -652,13 +651,11 @@ async def _protected_async_fn() -> None:
652651
653652@_core .enable_ki_protection
654653def _protected_gen_fn () -> Generator [None , None , None ]:
655- return
656654 yield
657655
658656
659657@_core .disable_ki_protection
660658async def _unprotected_async_gen_fn () -> AsyncGenerator [None , None ]:
661- return
662659 yield
663660
664661
@@ -669,20 +666,27 @@ async def _unprotected_async_fn() -> None:
669666
670667@_core .disable_ki_protection
671668def _unprotected_gen_fn () -> Generator [None , None , None ]:
672- return
673669 yield
674670
675671
672+ async def _consume_async_generator (agen : AsyncGenerator [None , None ]) -> None :
673+ try :
674+ with pytest .raises (StopAsyncIteration ):
675+ while True :
676+ await agen .asend (None )
677+ finally :
678+ await agen .aclose ()
679+
680+
676681def _consume_function_for_coverage (fn : Callable [..., object ]) -> None :
677682 result = fn ()
678683 if inspect .isasyncgen (result ):
679- with pytest .raises (StopAsyncIteration ):
680- result .asend (None ).send (None )
681- return
684+ result = _consume_async_generator (result )
682685
683686 assert inspect .isgenerator (result ) or inspect .iscoroutine (result )
684687 with pytest .raises (StopIteration ):
685- result .send (None )
688+ while True :
689+ result .send (None )
686690
687691
688692def test_enable_disable_ki_protection_passes_on_inspect_flags () -> None :
0 commit comments