Spaces:
Running on L40S
Running on L40S
File size: 516 Bytes
9f818c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import pytest
from cosmos_framework.utils.timer import Timer
def test_timer_decorator_resets_after_exception():
timer = Timer(measure_cpu=True, measure_cuda=False, debug=True)
calls = 0
@timer
def fail_once():
nonlocal calls
calls += 1
if calls == 1:
raise RuntimeError("first call failed")
return "ok"
with pytest.raises(RuntimeError, match="first call failed"):
fail_once()
assert timer.busy is False
assert fail_once() == "ok"
|