Tweak some tests for spurious failues
With the seeming cause that some cases occasionally raise `ExceptionGroup` instead of a (collapsed out) single error which, in those cases at least try to check that `.exceptions` has the original error.modden_spawn_from_client_req_XPS_BACKUP
							parent
							
								
									ededa2e88f
								
							
						
					
					
						commit
						8c39b8b124
					
				|  | @ -1,4 +1,4 @@ | |||
| # vim: ft=ini | ||||
| # vim: ft=conf | ||||
| # pytest.ini for tractor | ||||
| 
 | ||||
| [pytest] | ||||
|  |  | |||
|  | @ -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', | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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.. | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue