I have a function that intermittently fails during automated builds so I want to add some retries to it. The function is basically like this:
def myfunc():
try:
# do stuff
return 0
except:
return 1
I’ve tried using a mock with side_effect=[1, 1, 0]
which works fine, but I need it to actually “do stuff” on the third (successful) attempt.
It can be run multiple times, so it’s ok to run the function 3 times but return different exit codes on each run.
All I’ve managed to do so far is either mock the function and return different exit codes or just run the original function. I can’t figure out how to do both.
1