I am using the tenacity library to use its @retry decorator.
I am using this to make a function which makes a HTTP-request "repeat" multiple times in case of failure.
Here is a simple code snippet:
@retry(stop=stop_after_attempt(7), wait=wait_random_exponential(multiplier=1, max=60))
def func():
...
requests.post(...)
The function uses the tenacity wait-argument to wait some time in between calls.
The function together with the @retry-decorator seems to work fine.
But I also have a unit-test which checks that the function gets called indeed 7 times in case of a failure. This test takes a lot of time because of this wait in beetween tries.
Is it possible to somehow disable the wait-time only in the unit-test?
You can use unittest.mock module to mock some elements of tentacity library. In your case all decorators you use are classes e.g.
retryis a decorator class defined here. So it might be little bit tricky, but I think trying tomay help.