Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

how to check how many times retry function called in python

$
0
0

I'm using a retry decorator to run the test case if failed. So, want to know how many times the retry function called

   def retry(tries=3, delay=10):       def decorator(func):           @wraps(func)           def func_retry(*args, **kwargs):              n_tries, n_delay = tries, delay              output = error = None              while n_tries >= 1:                  try:                      output = func(*args, **kwargs)                      return output                  except AssertionError as e:                      n_tries = n_tries - 1                      error = e.__str__()                      print(f'Retry error: "{func.__name__}" due to "{error}". So, Retrying execution [{(tries - n_tries)}/{tries}] in {delay} second(s)...')                      time.sleep(n_delay)                   return output           return func_retry       return decorator

Sample function for testing purpose

   @retry()   def test():      assert "x" == "y"

I want to know how many times retry function in retry decorator calledlike retry.count using the decorator


Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>