forked from goodboy/tractor
1
0
Fork 0

Support `loglevel` fixture injection

For `pytest`, support defining a `loglevel` fixture value which will be
passed into internals when using `@tractor_test`.
loglevel_to_tractor_tests
Tyler Goodlet 2018-11-30 01:11:08 -05:00
parent 58ebacf0f7
commit f81e802219
1 changed files with 17 additions and 4 deletions

View File

@ -15,15 +15,28 @@ def tractor_test(fn):
async def test_whatever(): async def test_whatever():
await ... await ...
If an ``arb_addr`` (a socket addr tuple) is defined in the If fixtures:
`pytest` fixture space it will be automatically injected.
- ``arb_addr`` (a socket addr tuple where arbiter is listening)
- ``loglevel`` (logging level passed to tractor internals)
are defined in the `pytest` fixture space they will be automatically
injected to tests declaring these funcargs.
""" """
@wraps(fn) @wraps(fn)
def wrapper(*args, arb_addr=None, **kwargs): def wrapper(*args, loglevel=None, arb_addr=None, **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
# as `run()`
kwargs['arb_addr'] = arb_addr kwargs['arb_addr'] = arb_addr
if 'loglevel' in inspect.signature(fn).parameters:
# allows test suites to define a 'loglevel' fixture
# that activates the internal logging
kwargs['loglevel'] = loglevel
return run( return run(
partial(fn, *args, **kwargs), arbiter_addr=arb_addr) partial(fn, *args, **kwargs),
arbiter_addr=arb_addr, loglevel=loglevel
)
return wrapper return wrapper