From 32b10681a1dc51bb542803f59f5b083d68a54d8f Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 8 Jan 2021 20:49:38 -0500 Subject: [PATCH] Drop tractor.run() from @tractor_test --- tractor/testing/_tractor_test.py | 39 ++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/tractor/testing/_tractor_test.py b/tractor/testing/_tractor_test.py index 65f199f..734e367 100644 --- a/tractor/testing/_tractor_test.py +++ b/tractor/testing/_tractor_test.py @@ -2,7 +2,9 @@ import inspect import platform from functools import partial, wraps -from tractor import run +import trio +import tractor +# from tractor import run __all__ = ['tractor_test'] @@ -34,6 +36,7 @@ def tractor_test(fn): **kwargs ): # __tracebackhide__ = True + if 'arb_addr' in inspect.signature(fn).parameters: # injects test suite fixture value to test as well # as `run()` @@ -54,11 +57,33 @@ def tractor_test(fn): # set of subprocess spawning backends kwargs['start_method'] = start_method - return run( - partial(fn, *args, **kwargs), - arbiter_addr=arb_addr, - loglevel=loglevel, - start_method=start_method, - ) + if kwargs: + + # use explicit root actor start + + async def _main(): + async with tractor.open_root_actor( + # **kwargs, + arbiter_addr=arb_addr, + loglevel=loglevel, + start_method=start_method, + + # TODO: only enable when pytest is passed --pdb + # debug_mode=True, + + ) as actor: + await fn(*args, **kwargs) + + main = _main + + else: + # use implicit root actor start + main = partial(fn, *args, **kwargs), + + return trio.run(main) + # arbiter_addr=arb_addr, + # loglevel=loglevel, + # start_method=start_method, + # ) return wrapper