diff --git a/pytest.ini b/pytest.ini index 6a7e51f..b252722 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,4 +1,4 @@ -# vim: ft=ini +# vim: ft=conf # pytest.ini for tractor [pytest] diff --git a/tests/test_advanced_faults.py b/tests/test_advanced_faults.py index a48866e..f34738b 100644 --- a/tests/test_advanced_faults.py +++ b/tests/test_advanced_faults.py @@ -18,7 +18,10 @@ from conftest import ( @pytest.mark.parametrize( 'debug_mode', [False, True], - ids=['no_debug_mode', 'debug_mode'], + ids=[ + 'no_debug_mode', + 'debug_mode', + ], ) @pytest.mark.parametrize( 'ipc_break', diff --git a/tests/test_advanced_streaming.py b/tests/test_advanced_streaming.py index e869634..3134b9c 100644 --- a/tests/test_advanced_streaming.py +++ b/tests/test_advanced_streaming.py @@ -6,6 +6,7 @@ from collections import Counter import itertools import platform +import pytest import trio import tractor @@ -143,8 +144,16 @@ def test_dynamic_pub_sub(): try: trio.run(main) - except trio.TooSlowError: - pass + except ( + trio.TooSlowError, + ExceptionGroup, + ) as err: + if isinstance(err, ExceptionGroup): + for suberr in err.exceptions: + if isinstance(suberr, trio.TooSlowError): + break + else: + pytest.fail('Never got a `TooSlowError` ?') @tractor.context diff --git a/tests/test_infected_asyncio.py b/tests/test_infected_asyncio.py index 24bd371..1ac1fba 100644 --- a/tests/test_infected_asyncio.py +++ b/tests/test_infected_asyncio.py @@ -70,7 +70,7 @@ def test_trio_cancels_aio_on_actor_side(reg_addr): async def asyncio_actor( target: str, - expect_err: Optional[Exception] = None + expect_err: Exception|None = None ) -> None: @@ -114,10 +114,21 @@ def test_aio_simple_error(reg_addr): infect_asyncio=True, ) - with pytest.raises(RemoteActorError) as excinfo: + with pytest.raises( + expected_exception=(RemoteActorError, ExceptionGroup), + ) as excinfo: trio.run(main) err = excinfo.value + + # might get multiple `trio.Cancelled`s as well inside an inception + if isinstance(err, ExceptionGroup): + err = next(itertools.dropwhile( + lambda exc: not isinstance(exc, tractor.RemoteActorError), + err.exceptions + )) + assert err + assert isinstance(err, RemoteActorError) assert err.type == AssertionError @@ -290,11 +301,22 @@ def test_aio_cancelled_from_aio_causes_trio_cancelled(reg_addr): infect_asyncio=True, ) - with pytest.raises(RemoteActorError) as excinfo: + with pytest.raises( + expected_exception=(RemoteActorError, ExceptionGroup), + ) as excinfo: trio.run(main) + # might get multiple `trio.Cancelled`s as well inside an inception + err = excinfo.value + if isinstance(err, ExceptionGroup): + err = next(itertools.dropwhile( + lambda exc: not isinstance(exc, tractor.RemoteActorError), + err.exceptions + )) + assert err + # ensure boxed error is correct - assert excinfo.value.type == to_asyncio.AsyncioCancelled + assert err.type == to_asyncio.AsyncioCancelled # TODO: verify open_channel_from will fail on this.. diff --git a/tests/test_rpc.py b/tests/test_rpc.py index 1a46666..a18bcb0 100644 --- a/tests/test_rpc.py +++ b/tests/test_rpc.py @@ -1,6 +1,8 @@ -""" -RPC related -""" +''' +RPC (or maybe better labelled as "RTS: remote task scheduling"?) +related API and error checks. + +''' import itertools import pytest @@ -52,8 +54,13 @@ async def short_sleep(): (['tmp_mod'], 'import doggy', ModuleNotFoundError), (['tmp_mod'], '4doggy', SyntaxError), ], - ids=['no_mods', 'this_mod', 'this_mod_bad_func', 'fail_to_import', - 'fail_on_syntax'], + ids=[ + 'no_mods', + 'this_mod', + 'this_mod_bad_func', + 'fail_to_import', + 'fail_on_syntax', + ], ) def test_rpc_errors( reg_addr, @@ -127,7 +134,9 @@ def test_rpc_errors( run() else: # underlying errors aren't propagated upwards (yet) - with pytest.raises(remote_err) as err: + with pytest.raises( + expected_exception=(remote_err, ExceptionGroup), + ) as err: run() # get raw instance from pytest wrapper