Say you have:
Class MyClass:
@backoff.on_exception(backoff.expo, Exception, max_tries=20)
def my_method():
do_something()
For the purposes of testing my_method, you only want to retry 2 times. I have not found a way to patch, wrap, etc. that backoff.on_exception. I am wondering if anyone else can help? Thanks
One option would be to use Runtime Configuration for the
max_triesparameter. The documentation says "decorator functions can be passed callables which are evaluated at runtime to obtain the value." You could set an environment variable that the callable checks to determine whatmax_triesshould be set to. It might be as simple as checking an existingENVIRONMENTvariable, if you always do your testing locally. Or you could create a new variableTESTINGthat is False by default, but switched to True by your tests.Then your decorator would look like:
And the lookup function would check the environment variable: