Add a `spawn_method` dynamic fixture

spawn_method_support
Tyler Goodlet 2019-03-06 00:36:37 -05:00
parent 7014a07986
commit 483ae42a46
2 changed files with 22 additions and 2 deletions

View File

@ -28,3 +28,11 @@ def loglevel(request):
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def arb_addr(): def arb_addr():
return _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')

View File

@ -24,7 +24,13 @@ def tractor_test(fn):
injected to tests declaring these funcargs. injected to tests declaring these funcargs.
""" """
@wraps(fn) @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 # __tracebackhide__ = True
if 'arb_addr' in inspect.signature(fn).parameters: if 'arb_addr' in inspect.signature(fn).parameters:
# injects test suite fixture value to test as well # 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 # allows test suites to define a 'loglevel' fixture
# that activates the internal logging # that activates the internal logging
kwargs['loglevel'] = loglevel 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( return run(
partial(fn, *args, **kwargs), partial(fn, *args, **kwargs),
arbiter_addr=arb_addr, loglevel=loglevel arbiter_addr=arb_addr,
loglevel=loglevel,
spawn_method=spawn_method,
) )
return wrapper return wrapper