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?
After reading the thread in tenacity repo (thanks @DanEEStar for starting it!), I came up with the following code:
I use
pytest-specific features in this test. Probably, it could be useful as an example for someone, at least for future me.