Does pytest have something like a timer test?
i.e.
@pytest.mark.timer(60)
def test_this_code_runs_in_less_than_x():
bla()
which will fail if bla executes for more than 60 seconds?
I can implement this easily with my own decorator, e.g.:
import time, threading
def timeout(func):
def wrapper():
start_time = time.time()
timeout = start_time + 1
th = threading.Thread(target=func)
th.start()
while time.time() < timeout and th.isAlive():
pass
if th.isAlive():
raise TimeoutError()
th.join()
return wrapper
@timeout
def _test():
time.sleep(2)
def test_should_fail_after_one_second():
_test()
but I'm not looking to invent the wheel...
I know pytest can have a --timeout param, but I'm looking for something to be a part of the test definition, not a configurable parameter that affects ALL tests