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
| from functools import wraps, partial
|
| from .. import _core
| from ..abc import Clock, Instrument
|
|
| # Use:
| #
| # @trio_test
| # async def test_whatever():
| # await ...
| #
| # Also: if a pytest fixture is passed in that subclasses the Clock abc, then
| # that clock is passed to trio.run().
| def trio_test(fn):
| @wraps(fn)
| def wrapper(**kwargs):
| __tracebackhide__ = True
| clocks = [c for c in kwargs.values() if isinstance(c, Clock)]
| if not clocks:
| clock = None
| elif len(clocks) == 1:
| clock = clocks[0]
| else:
| raise ValueError("too many clocks spoil the broth!")
| instruments = [i for i in kwargs.values() if isinstance(i, Instrument)]
| return _core.run(partial(fn, **kwargs), clock=clock, instruments=instruments)
|
| return wrapper
|
|