forked from goodboy/tractor
1
0
Fork 0

Drop tractor.run() from @tractor_test

implicit_runtime
Tyler Goodlet 2021-01-08 20:49:38 -05:00
parent 41a4de5af2
commit 32b10681a1
1 changed files with 32 additions and 7 deletions

View File

@ -2,7 +2,9 @@ import inspect
import platform import platform
from functools import partial, wraps from functools import partial, wraps
from tractor import run import trio
import tractor
# from tractor import run
__all__ = ['tractor_test'] __all__ = ['tractor_test']
@ -34,6 +36,7 @@ def tractor_test(fn):
**kwargs **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 # injects test suite fixture value to test as well
# as `run()` # as `run()`
@ -54,11 +57,33 @@ def tractor_test(fn):
# set of subprocess spawning backends # set of subprocess spawning backends
kwargs['start_method'] = start_method kwargs['start_method'] = start_method
return run( if kwargs:
partial(fn, *args, **kwargs),
arbiter_addr=arb_addr, # use explicit root actor start
loglevel=loglevel,
start_method=start_method, 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 return wrapper