-
-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix test_run_process_internal_error, add test_bad_deliver_cancel
- Loading branch information
Showing
1 changed file
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
import pytest | ||
|
||
import trio | ||
from trio.testing import RaisesGroup | ||
from trio.testing import Matcher, RaisesGroup | ||
|
||
from .. import ( | ||
Event, | ||
|
@@ -565,6 +565,27 @@ async def custom_deliver_cancel(proc: Process) -> None: | |
assert custom_deliver_cancel_called | ||
|
||
|
||
def test_bad_deliver_cancel() -> None: | ||
async def custom_deliver_cancel(proc: Process) -> None: | ||
proc.terminate() | ||
raise ValueError("foo") | ||
|
||
async def do_stuff() -> None: | ||
async with _core.open_nursery() as nursery: | ||
nursery.start_soon( | ||
partial(run_process, SLEEP(9999), deliver_cancel=custom_deliver_cancel) | ||
) | ||
await wait_all_tasks_blocked() | ||
nursery.cancel_scope.cancel() | ||
|
||
# double wrap from our nursery + the internal nursery | ||
with RaisesGroup(RaisesGroup(Matcher(ValueError, "^foo$"))): | ||
_core.run(do_stuff, strict_exception_groups=True) | ||
|
||
with pytest.raises(ValueError, match="^foo$"): | ||
_core.run(do_stuff, strict_exception_groups=False) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jakkdl
Author
Member
|
||
|
||
|
||
async def test_warn_on_failed_cancel_terminate(monkeypatch: pytest.MonkeyPatch) -> None: | ||
original_terminate = Process.terminate | ||
|
||
|
@@ -630,9 +651,8 @@ async def very_broken_open(*args: object, **kwargs: object) -> str: | |
return "oops" | ||
|
||
monkeypatch.setattr(trio._subprocess, "open_process", very_broken_open) | ||
with pytest.raises(trio.TrioInternalError) as excinfo: | ||
with RaisesGroup(AttributeError, AttributeError): | ||
await run_process(EXIT_TRUE, capture_stdout=True) | ||
assert RaisesGroup(AttributeError, AttributeError).matches(excinfo.value.__cause__) | ||
|
||
|
||
# regression test for #2209 | ||
|
It's good to see this working, but it's not quite what I had described. I had set
strict_exception_groups=False
directly at the nursery in_subprocess._run_process
, while the trio.run argument was True. I would be thrilled to be wrong about that, but I don't think it's an issue for this PR anymore.