Skip to content

Commit 22e4765

Browse files
committed
fix test_run_process_internal_error, add test_bad_deliver_cancel
1 parent 0547313 commit 22e4765

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/trio/_tests/test_subprocess.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import pytest
2323

2424
import trio
25-
from trio.testing import RaisesGroup
25+
from trio.testing import Matcher, RaisesGroup
2626

2727
from .. import (
2828
Event,
@@ -565,6 +565,27 @@ async def custom_deliver_cancel(proc: Process) -> None:
565565
assert custom_deliver_cancel_called
566566

567567

568+
def test_bad_deliver_cancel() -> None:
569+
async def custom_deliver_cancel(proc: Process) -> None:
570+
proc.terminate()
571+
raise ValueError("foo")
572+
573+
async def do_stuff() -> None:
574+
async with _core.open_nursery() as nursery:
575+
nursery.start_soon(
576+
partial(run_process, SLEEP(9999), deliver_cancel=custom_deliver_cancel)
577+
)
578+
await wait_all_tasks_blocked()
579+
nursery.cancel_scope.cancel()
580+
581+
# double wrap from our nursery + the internal nursery
582+
with RaisesGroup(RaisesGroup(Matcher(ValueError, "^foo$"))):
583+
_core.run(do_stuff, strict_exception_groups=True)
584+
585+
with pytest.raises(ValueError, match="^foo$"):
586+
_core.run(do_stuff, strict_exception_groups=False)
587+
588+
568589
async def test_warn_on_failed_cancel_terminate(monkeypatch: pytest.MonkeyPatch) -> None:
569590
original_terminate = Process.terminate
570591

@@ -630,9 +651,8 @@ async def very_broken_open(*args: object, **kwargs: object) -> str:
630651
return "oops"
631652

632653
monkeypatch.setattr(trio._subprocess, "open_process", very_broken_open)
633-
with pytest.raises(trio.TrioInternalError) as excinfo:
654+
with RaisesGroup(AttributeError, AttributeError):
634655
await run_process(EXIT_TRUE, capture_stdout=True)
635-
assert RaisesGroup(AttributeError, AttributeError).matches(excinfo.value.__cause__)
636656

637657

638658
# regression test for #2209

0 commit comments

Comments
 (0)