|
22 | 22 | import pytest |
23 | 23 |
|
24 | 24 | import trio |
25 | | -from trio.testing import RaisesGroup |
| 25 | +from trio.testing import Matcher, RaisesGroup |
26 | 26 |
|
27 | 27 | from .. import ( |
28 | 28 | Event, |
@@ -565,6 +565,27 @@ async def custom_deliver_cancel(proc: Process) -> None: |
565 | 565 | assert custom_deliver_cancel_called |
566 | 566 |
|
567 | 567 |
|
| 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 | + |
568 | 589 | async def test_warn_on_failed_cancel_terminate(monkeypatch: pytest.MonkeyPatch) -> None: |
569 | 590 | original_terminate = Process.terminate |
570 | 591 |
|
@@ -630,9 +651,8 @@ async def very_broken_open(*args: object, **kwargs: object) -> str: |
630 | 651 | return "oops" |
631 | 652 |
|
632 | 653 | monkeypatch.setattr(trio._subprocess, "open_process", very_broken_open) |
633 | | - with pytest.raises(trio.TrioInternalError) as excinfo: |
| 654 | + with RaisesGroup(AttributeError, AttributeError): |
634 | 655 | await run_process(EXIT_TRUE, capture_stdout=True) |
635 | | - assert RaisesGroup(AttributeError, AttributeError).matches(excinfo.value.__cause__) |
636 | 656 |
|
637 | 657 |
|
638 | 658 | # regression test for #2209 |
|
0 commit comments