Merge pull request #48 from tgoodlet/loglevel_to_tractor_tests

Support `loglevel` fixture injection
remote_module_errors
goodboy 2018-11-30 08:34:52 -05:00 committed by GitHub
commit 26ab45636e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -15,15 +15,28 @@ def tractor_test(fn):
async def test_whatever():
await ...
If an ``arb_addr`` (a socket addr tuple) is defined in the
`pytest` fixture space it will be automatically injected.
If fixtures:
- ``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)
def wrapper(*args, arb_addr=None, **kwargs):
def wrapper(*args, loglevel=None, arb_addr=None, **kwargs):
# __tracebackhide__ = True
if 'arb_addr' in inspect.signature(fn).parameters:
# injects test suite fixture value to test as well
# as `run()`
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(
partial(fn, *args, **kwargs), arbiter_addr=arb_addr)
partial(fn, *args, **kwargs),
arbiter_addr=arb_addr, loglevel=loglevel
)
return wrapper