diff --git a/tests/conftest.py b/tests/conftest.py index 8e9a67c..c9159f0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -41,11 +41,14 @@ def tractor_test(fn): *args, loglevel=None, reg_addr=None, - start_method=None, + start_method: str|None = None, + debug_mode: bool = False, **kwargs ): # __tracebackhide__ = True + # NOTE: inject ant test func declared fixture + # names by manually checking! if 'reg_addr' in inspect.signature(fn).parameters: # injects test suite fixture value to test as well # as `run()` @@ -64,10 +67,14 @@ def tractor_test(fn): # set of subprocess spawning backends kwargs['start_method'] = start_method + if 'debug_mode' in inspect.signature(fn).parameters: + # set of subprocess spawning backends + kwargs['debug_mode'] = debug_mode + + if kwargs: # use explicit root actor start - async def _main(): async with tractor.open_root_actor( # **kwargs, @@ -76,7 +83,7 @@ def tractor_test(fn): start_method=start_method, # TODO: only enable when pytest is passed --pdb - # debug_mode=True, + debug_mode=debug_mode, ): await fn(*args, **kwargs) @@ -130,22 +137,43 @@ def examples_dir() -> pathlib.Path: def pytest_addoption(parser): parser.addoption( - "--ll", action="store", dest='loglevel', + "--ll", + action="store", + dest='loglevel', default='ERROR', help="logging level to set when testing" ) parser.addoption( - "--spawn-backend", action="store", dest='spawn_backend', + "--spawn-backend", + action="store", + dest='spawn_backend', default='trio', help="Processing spawning backend to use for test run", ) + parser.addoption( + "--tpdb", "--debug-mode", + action="store_true", + dest='tractor_debug_mode', + # default=False, + help=( + 'Enable a flag that can be used by tests to to set the ' + '`debug_mode: bool` for engaging the internal ' + 'multi-proc debugger sys.' + ), + ) + def pytest_configure(config): backend = config.option.spawn_backend tractor._spawn.try_set_start_method(backend) +@pytest.fixture(scope='session') +def debug_mode(request): + return request.config.option.tractor_debug_mode + + @pytest.fixture(scope='session', autouse=True) def loglevel(request): orig = tractor.log._default_loglevel