2018-11-26 16:20:53 +00:00
|
|
|
import inspect
|
|
|
|
from functools import partial, wraps
|
|
|
|
|
2018-11-26 16:26:04 +00:00
|
|
|
from .. import run
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ['tractor_test']
|
2018-11-26 16:20:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
def tractor_test(fn):
|
|
|
|
"""
|
|
|
|
Use:
|
|
|
|
|
|
|
|
@tractor_test
|
|
|
|
async def test_whatever():
|
|
|
|
await ...
|
|
|
|
|
2018-11-30 06:11:08 +00:00
|
|
|
If fixtures:
|
|
|
|
|
|
|
|
- ``arb_addr`` (a socket addr tuple where arbiter is listening)
|
|
|
|
- ``loglevel`` (logging level passed to tractor internals)
|
2020-01-27 02:36:08 +00:00
|
|
|
- ``start_method`` (subprocess spawning backend)
|
2018-11-30 06:11:08 +00:00
|
|
|
|
|
|
|
are defined in the `pytest` fixture space they will be automatically
|
|
|
|
injected to tests declaring these funcargs.
|
2018-11-26 16:20:53 +00:00
|
|
|
"""
|
|
|
|
@wraps(fn)
|
2019-03-06 05:36:37 +00:00
|
|
|
def wrapper(
|
|
|
|
*args,
|
|
|
|
loglevel=None,
|
|
|
|
arb_addr=None,
|
2020-01-24 05:54:19 +00:00
|
|
|
start_method='trio_run_in_process',
|
2019-03-06 05:36:37 +00:00
|
|
|
**kwargs
|
|
|
|
):
|
2018-11-26 16:20:53 +00:00
|
|
|
# __tracebackhide__ = True
|
|
|
|
if 'arb_addr' in inspect.signature(fn).parameters:
|
2018-11-30 06:11:08 +00:00
|
|
|
# injects test suite fixture value to test as well
|
|
|
|
# as `run()`
|
2018-11-26 16:20:53 +00:00
|
|
|
kwargs['arb_addr'] = arb_addr
|
2018-11-30 06:11:08 +00:00
|
|
|
if 'loglevel' in inspect.signature(fn).parameters:
|
|
|
|
# allows test suites to define a 'loglevel' fixture
|
|
|
|
# that activates the internal logging
|
|
|
|
kwargs['loglevel'] = loglevel
|
2019-03-09 01:06:16 +00:00
|
|
|
if 'start_method' in inspect.signature(fn).parameters:
|
2020-01-27 02:36:08 +00:00
|
|
|
# set of subprocess spawning backends
|
2019-03-09 01:06:16 +00:00
|
|
|
kwargs['start_method'] = start_method
|
2018-11-26 16:20:53 +00:00
|
|
|
return run(
|
2018-11-30 06:11:08 +00:00
|
|
|
partial(fn, *args, **kwargs),
|
2019-03-06 05:36:37 +00:00
|
|
|
arbiter_addr=arb_addr,
|
|
|
|
loglevel=loglevel,
|
2019-03-09 01:06:16 +00:00
|
|
|
start_method=start_method,
|
2018-11-30 06:11:08 +00:00
|
|
|
)
|
2018-11-26 16:20:53 +00:00
|
|
|
|
|
|
|
return wrapper
|