Skip to content

Commit 1e10e62

Browse files
committed
'return; yield' isn't considered covered
1 parent 9bbaef0 commit 1e10e62

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/trio/_core/_tests/test_ki.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ def __eq__(self, other: object) -> bool:
641641

642642
@_core.enable_ki_protection
643643
async 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
654653
def _protected_gen_fn() -> Generator[None, None, None]:
655-
return
656654
yield
657655

658656

659657
@_core.disable_ki_protection
660658
async 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
671668
def _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+
676681
def _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

688692
def test_enable_disable_ki_protection_passes_on_inspect_flags() -> None:

0 commit comments

Comments
 (0)