From 347591c3488dddd036e51d592dbdb0510e9fbbca Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 13 Oct 2022 17:00:24 -0400 Subject: [PATCH] Expect egs in tests which retreive portal results --- tests/test_cancellation.py | 26 ++++++++++++++++++++++---- tests/test_infected_asyncio.py | 15 +++++++++------ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/tests/test_cancellation.py b/tests/test_cancellation.py index ce260c1..657ab8e 100644 --- a/tests/test_cancellation.py +++ b/tests/test_cancellation.py @@ -60,23 +60,41 @@ def test_remote_error(arb_addr, args_err): arbiter_addr=arb_addr, ) as nursery: + # on a remote type error caused by bad input args + # this should raise directly which means we **don't** get + # an exception group outside the nursery since the error + # here and the far end task error are one in the same? portal = await nursery.run_in_actor( assert_err, name='errorer', **args ) # get result(s) from main task try: + # this means the root actor will also raise a local + # parent task error and thus an eg will propagate out + # of this actor nursery. await portal.result() except tractor.RemoteActorError as err: assert err.type == errtype print("Look Maa that actor failed hard, hehh") raise - with pytest.raises(tractor.RemoteActorError) as excinfo: - trio.run(main) + # ensure boxed errors + if args: + with pytest.raises(tractor.RemoteActorError) as excinfo: + trio.run(main) - # ensure boxed error is correct - assert excinfo.value.type == errtype + assert excinfo.value.type == errtype + + else: + # the root task will also error on the `.result()` call + # so we expect an error from there AND the child. + with pytest.raises(BaseExceptionGroup) as excinfo: + trio.run(main) + + # ensure boxed errors + for exc in excinfo.value.exceptions: + assert exc.type == errtype def test_multierror(arb_addr): diff --git a/tests/test_infected_asyncio.py b/tests/test_infected_asyncio.py index ac8cbcd..775ee98 100644 --- a/tests/test_infected_asyncio.py +++ b/tests/test_infected_asyncio.py @@ -8,6 +8,7 @@ import builtins import itertools import importlib +from exceptiongroup import BaseExceptionGroup import pytest import trio import tractor @@ -409,11 +410,12 @@ def test_trio_error_cancels_intertask_chan(arb_addr): # should trigger remote actor error await portal.result() - with pytest.raises(RemoteActorError) as excinfo: + with pytest.raises(BaseExceptionGroup) as excinfo: trio.run(main) - # ensure boxed error is correct - assert excinfo.value.type == Exception + # ensure boxed errors + for exc in excinfo.value.exceptions: + assert exc.type == Exception def test_trio_closes_early_and_channel_exits(arb_addr): @@ -442,11 +444,12 @@ def test_aio_errors_and_channel_propagates_and_closes(arb_addr): # should trigger remote actor error await portal.result() - with pytest.raises(RemoteActorError) as excinfo: + with pytest.raises(BaseExceptionGroup) as excinfo: trio.run(main) - # ensure boxed error is correct - assert excinfo.value.type == Exception + # ensure boxed errors + for exc in excinfo.value.exceptions: + assert exc.type == Exception @tractor.context