forked from goodboy/tractor
1
0
Fork 0
tractor/tests/conftest.py

47 lines
968 B
Python
Raw Permalink Normal View History

2018-07-11 23:25:30 +00:00
"""
``tractor`` testing!!
"""
import random
from functools import partial, wraps
2018-07-11 23:25:30 +00:00
import pytest
import tractor
_arb_addr = '127.0.0.1', random.randint(1000, 9999)
2018-07-11 23:25:30 +00:00
def pytest_addoption(parser):
parser.addoption("--ll", action="store", dest='loglevel',
default=None, help="logging level to set when testing")
@pytest.fixture(scope='session', autouse=True)
def loglevel(request):
2018-07-14 20:09:05 +00:00
orig = tractor.log._default_loglevel
level = tractor.log._default_loglevel = request.config.option.loglevel
2018-07-11 23:25:30 +00:00
yield level
2018-07-14 20:09:05 +00:00
tractor.log._default_loglevel = orig
@pytest.fixture(scope='session')
def 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