Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2019.2] The flaky decorator should go through (setUp|tearDown)() at each attempt #53269

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/support/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,23 @@ def test_sometimes_works(self):
def wrap(cls):
for attempt in range(0, attempts):
try:
if attempt > 0:
# Run through setUp again
# We only run it after the first iteration(>0) because the regular
# test runner will have already ran setUp the first time
setup = getattr(cls, 'setUp', None)
if callable(setup):
setup()
return caller(cls)
except Exception as exc:
if attempt >= attempts -1:
# We won't try to run tearDown once the attempts are exhausted
# because the regular test runner will do that for us
raise exc
# Run through tearDown again
teardown = getattr(cls, 'tearDown', None)
if callable(teardown):
teardown()
backoff_time = attempt ** 2
log.info(
'Found Exception. Waiting %s seconds to retry.',
Expand Down