Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions trio/testing/_trio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@
#
# 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)
def trio_test(fn=None, *, run=_core.run):
def decorator(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 run(partial(fn, **kwargs), clock=clock, instruments=instruments)

return wrapper
return wrapper

if fn is None:
return decorator

return decorator(fn)