This commit is contained in:
Kovid Goyal 2026-01-10 05:18:36 +05:30
parent 99c49f4df1
commit ece6f7ea6b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -29,17 +29,15 @@ def retry(max_attempts=3, delay=0):
def decorator(test_func):
@wraps(test_func)
def wrapper(*args, **kwargs):
last_exception = None
for attempt in range(max_attempts):
try:
return test_func(*args, **kwargs)
except AssertionError as e:
last_exception = e
if attempt < max_attempts - 1:
print(f'Retry ({attempt + 1}/{max_attempts-1}) on {test_func} failure with error: {e}')
time.sleep(delay)
print(f'Retry {attempt + 1}/{max_attempts - 1}')
else:
raise last_exception
raise
return wrapper
return decorator