def test_func_that_raises_wrong_exception_type_should_raise(self): with raises(Exception) as e: retry.call( get_dummy_func(5), exceptions=[TypeError], ) assert str(e.value) == 'Test Error 1'
def test_retry_with_wait_function(self, mock_sleep): retry.call(get_dummy_func(), wait=lambda n: n) mock_sleep.assert_called_with(4)
def test_retry_func_with_kwarg(self): result = retry.call(get_dummy_func(), kwargs={'foo': 'bar'}) assert result == (CallCounter(5, 4), (), {'foo': 'bar'})
def test_retry_func_with_postional_arg(self): result = retry.call(get_dummy_func(), args=['foo']) assert result == (CallCounter(5, 4), ('foo', ), {})
def test_func_with_positional_arg(self): assert retry.call(lambda x: x, args=['bar']) == 'bar'
def test_func_that_fails_check_raises(self): with raises(Exception) as e: retry.call(get_dummy_func(5), check=lambda e, c: c != 3) assert str(e.value) == 'Test Error 3'
def test_func_that_passes_check_does_not_raise(self): result = retry.call( get_dummy_func(), check=lambda e, c: True, ) assert result == (CallCounter(5, 4), (), {})
def test_func_that_raises_too_many_time_raises(self): with raises(Exception) as e: retry.call(get_dummy_func(50)) assert str(e.value) == 'Test Error 5'
def test_retry_func_with_no_args(self): result = retry.call(get_dummy_func()) assert result == (CallCounter(5, 4), (), {})