forked from sublee/trueskill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
50 lines (41 loc) · 1.66 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
from __future__ import with_statement
from trueskill.backends import available_backends
backends = available_backends()
def pytest_addoption(parser):
parser.addoption('--backend', action='append', default=[])
def pytest_generate_tests(metafunc):
if getattr(metafunc.function, '_various_backends', False):
available = [None if str(backend).lower() == 'none' else backend
for backend in metafunc.config.option.backend or backends]
selected = metafunc.function._various_backends
if selected is True:
parametrized_backends = available
elif selected is False:
parametrized_backends = None
else:
parametrized_backends = set(available).intersection(selected)
metafunc.parametrize('backend', parametrized_backends)
def various_backends(backends=None):
import inspect
from trueskillhelpers import substituted_trueskill
if hasattr(backends, '__call__'):
return various_backends(True)(backends)
def decorator(f):
def wrapped(backend, *args, **kwargs):
try:
sig = inspect.signature(f)
except AttributeError:
spec = inspect.getargspec(f)
params = spec[0]
else:
params = sig.parameters
if 'backend' in params:
kwargs.setdefault('backend', backend)
with substituted_trueskill(backend=backend):
return f(*args, **kwargs)
wrapped.__name__ = f.__name__
wrapped.__doc__ = f.__doc__
wrapped._various_backends = backends
return wrapped
return decorator