Skip to content

Instantly share code, notes, and snippets.

@adiroiban adiroiban/

Created Mar 24, 2018
What would you like to do?
flaky decorator
def flaky(count=3, os_version=None):
A decorator generator to retry a test if it fails in one of the OS from
When `os_version` is None it will retry on any OS.
It will not work with any tests.
The setUp and tearDown is only called once and not called between
The cleanups are called between retries.
def decorator(test_item):
This is the actual decorator.
def wrapper(self):
Wrap the test method to execute it multiple times.
error = None
for _ in range(count): # pragma: no branch
# All good. Stop trying.
except AssertionError as error: # noqa:cover
if (
os_version and
ServerTestCase.os_version not in os_version
# The current OS is not targed as flaky, so fail
# right away.
raise error
# Run cleanup and try again.
except Exception:
Just ignore any cleanup error which occurred for a
failed tests.
If the tests succeeds, the cleanup is not called
from here, but as part of the normal test run.
# Let the other thread to execute.
# We tried 3 times and still got a failure.
raise error # noqa:cover
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.