EDIT: Since tenacity is a more recent for of retrying, this question can be considered a duplicate of the linked question, with the solution being to upgrade to tenacity.
Similar to this question, I want to unittest a function in python that has a retry decorator:
from retrying import retry # from retrying pypi module
WAIT_EXPONENTIAL_MULTIPLIER = 4 * 1000 # ms
STOP_MAX_ATTEMPT_NUMBER = 5
@retry(
wait_exponential_multiplier=WAIT_EXPONENTIAL_MULTIPLIER,
stop_max_attempt_number=STOP_MAX_ATTEMPT_NUMBER
)
def get_from_remote(key):
raise ValueError() # for example
In my unittest, I want to call this function sometimes without retrying at all, sometimes with different parameters.
I tried setting the variables in setUp()/tearDown()
, but it did not work. I tried patching the retry decorator, but it also did not work.