Move `tractor_test` to new module
parent
b0f7e6a954
commit
0879150399
|
@ -2,10 +2,10 @@
|
||||||
``tractor`` testing!!
|
``tractor`` testing!!
|
||||||
"""
|
"""
|
||||||
import random
|
import random
|
||||||
from functools import partial, wraps
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import tractor
|
import tractor
|
||||||
|
from tractor._tractor_test import tractor_test
|
||||||
|
|
||||||
|
|
||||||
pytest_plugins = ['pytester']
|
pytest_plugins = ['pytester']
|
||||||
|
@ -28,20 +28,3 @@ def loglevel(request):
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def arb_addr():
|
def arb_addr():
|
||||||
return _arb_addr
|
return _arb_addr
|
||||||
|
|
||||||
|
|
||||||
def tractor_test(fn):
|
|
||||||
"""
|
|
||||||
Use:
|
|
||||||
|
|
||||||
@tractor_test
|
|
||||||
async def test_whatever():
|
|
||||||
await ...
|
|
||||||
"""
|
|
||||||
@wraps(fn)
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
# __tracebackhide__ = True
|
|
||||||
return tractor.run(
|
|
||||||
partial(fn, *args, **kwargs), arbiter_addr=_arb_addr)
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ import subprocess
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import tractor
|
import tractor
|
||||||
|
|
||||||
|
|
||||||
from conftest import tractor_test
|
from conftest import tractor_test
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,8 +70,9 @@ async def test_cancel_remote_arbiter(daemon, arb_addr):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@tractor_test
|
async def test_register_duplicate_name(daemon, arb_addr):
|
||||||
async def test_register_duplicate_name(daemon):
|
|
||||||
|
async def main():
|
||||||
assert not tractor.current_actor().is_arbiter
|
assert not tractor.current_actor().is_arbiter
|
||||||
async with tractor.open_nursery() as n:
|
async with tractor.open_nursery() as n:
|
||||||
p1 = await n.start_actor('doggy')
|
p1 = await n.start_actor('doggy')
|
||||||
|
@ -83,3 +82,7 @@ async def test_register_duplicate_name(daemon):
|
||||||
assert portal.channel.uid in (p2.channel.uid, p1.channel.uid)
|
assert portal.channel.uid in (p2.channel.uid, p1.channel.uid)
|
||||||
|
|
||||||
await n.cancel()
|
await n.cancel()
|
||||||
|
|
||||||
|
# run it manually since we want to start **after**
|
||||||
|
# the other "daemon" program
|
||||||
|
tractor.run(main, arb_addr=arbiter_addr)
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import inspect
|
||||||
|
from functools import partial, wraps
|
||||||
|
|
||||||
|
from . import run
|
||||||
|
|
||||||
|
|
||||||
|
def tractor_test(fn):
|
||||||
|
"""
|
||||||
|
Use:
|
||||||
|
|
||||||
|
@tractor_test
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
@wraps(fn)
|
||||||
|
def wrapper(*args, arb_addr=None, **kwargs):
|
||||||
|
# __tracebackhide__ = True
|
||||||
|
if 'arb_addr' in inspect.signature(fn).parameters:
|
||||||
|
kwargs['arb_addr'] = arb_addr
|
||||||
|
return run(
|
||||||
|
partial(fn, *args, **kwargs), arbiter_addr=arb_addr)
|
||||||
|
|
||||||
|
return wrapper
|
Loading…
Reference in New Issue