From f81e802219a6c506d6c09eb4379bffae14a0b7bc Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 30 Nov 2018 01:11:08 -0500 Subject: [PATCH] Support `loglevel` fixture injection For `pytest`, support defining a `loglevel` fixture value which will be passed into internals when using `@tractor_test`. --- tractor/testing/_tractor_test.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tractor/testing/_tractor_test.py b/tractor/testing/_tractor_test.py index 05e0b24..40a658a 100644 --- a/tractor/testing/_tractor_test.py +++ b/tractor/testing/_tractor_test.py @@ -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