retry icon indicating copy to clipboard operation
retry copied to clipboard

Overriding retry values for testing

Open jonatanskogsfors opened this issue 3 years ago • 2 comments

Calling a function decorated with @retry in a unittest can potentially take a long while if you want to test error handling. Is there (or could there be) a convenient way to override e.g. delay? Since the decorators are run at import (right?) it is not as easy as using a constant.

jonatanskogsfors avatar Dec 02 '20 15:12 jonatanskogsfors

@patch.object(retry.api.time, 'sleep')

Tjorriemorrie avatar Mar 24 '21 12:03 Tjorriemorrie

If you're using pytest, you can drop this in conftest.py:

@pytest.fixture(scope='session', autouse=True)
def patch_retry():
  with mock.patch.object(retry.api.time, 'sleep'):
    yield

lcarva avatar Jul 14 '21 20:07 lcarva