From 483ae42a46504cff67a7326660e48803efcc5789 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 6 Mar 2019 00:36:37 -0500 Subject: [PATCH] Add a `spawn_method` dynamic fixture --- tests/conftest.py | 8 ++++++++ tractor/testing/_tractor_test.py | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 97dccd7..22c77f8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,3 +28,11 @@ def loglevel(request): @pytest.fixture(scope='session') def arb_addr(): return _arb_addr + + +def pytest_generate_tests(metafunc): + if 'spawn_method' in metafunc.fixturenames: + from multiprocessing import get_all_start_methods + methods = get_all_start_methods() + methods.remove('fork') + metafunc.parametrize("spawn_method", methods, scope='module') diff --git a/tractor/testing/_tractor_test.py b/tractor/testing/_tractor_test.py index 40a658a..341d446 100644 --- a/tractor/testing/_tractor_test.py +++ b/tractor/testing/_tractor_test.py @@ -24,7 +24,13 @@ def tractor_test(fn): injected to tests declaring these funcargs. """ @wraps(fn) - def wrapper(*args, loglevel=None, arb_addr=None, **kwargs): + def wrapper( + *args, + loglevel=None, + arb_addr=None, + spawn_method='forkserver', + **kwargs + ): # __tracebackhide__ = True if 'arb_addr' in inspect.signature(fn).parameters: # injects test suite fixture value to test as well @@ -34,9 +40,15 @@ def tractor_test(fn): # allows test suites to define a 'loglevel' fixture # that activates the internal logging kwargs['loglevel'] = loglevel + if 'spawn_method' in inspect.signature(fn).parameters: + # allows test suites to define a 'loglevel' fixture + # that activates the internal logging + kwargs['spawn_method'] = spawn_method return run( partial(fn, *args, **kwargs), - arbiter_addr=arb_addr, loglevel=loglevel + arbiter_addr=arb_addr, + loglevel=loglevel, + spawn_method=spawn_method, ) return wrapper