Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@retry(5, 0)
def sleep_like_a_baby():
global COUNTER
if COUNTER < 3:
COUNTER += 1
raise Exception("sleeping")
return []
@retry(5, -1)
def fail_negative_sleep():
raise_exception()
def test_wrong_parameter():
with pytest.raises(ValueError) as ex:
retry(-1, 1)
assert str(ex.value) == 'retry_count have to be positive'
with pytest.raises(ValueError) as ex:
retry(0, 1)
assert str(ex.value) == 'retry_count have to be positive'
@retry(5, -1)
def fail_negative_sleep():
raise_exception()
with pytest.raises(ValueError) as ex:
fail_negative_sleep()
assert str(ex.value) == 'sleep length must be non-negative'
@retry(5, 0)
def always_success():
global COUNTER
COUNTER = COUNTER + 1
return 42
@retry(5, 0)
def always_raise_exception():
raise_exception()
@retry(4, .5)
def fail_and_sleep():
raise_exception()
def test_wrong_parameter():
with pytest.raises(ValueError) as ex:
retry(-1, 1)
assert str(ex.value) == 'retry_count have to be positive'
with pytest.raises(ValueError) as ex:
retry(0, 1)
assert str(ex.value) == 'retry_count have to be positive'
@retry(5, -1)
def fail_negative_sleep():
raise_exception()
with pytest.raises(ValueError) as ex:
fail_negative_sleep()
assert str(ex.value) == 'sleep length must be non-negative'