-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add EMTEST_RETRY_COUNT to force retrying failed tests #25565
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import common | ||
import os | ||
import unittest | ||
|
||
EMTEST_RETRY_COUNT = int(os.getenv('EMTEST_RETRY_COUNT', '0')) | ||
|
||
|
||
class RetryableTestCase(unittest.TestCase): | ||
'''This class patches in to the Python unittest TestCase object to incorporate | ||
support for an environment variable EMTEST_RETRY_COUNT=x, which enables a | ||
failed test to be automatically re-run to test if the failure might have been | ||
due to an instability.''' | ||
|
||
def run(self, result=None): | ||
retries_left = EMTEST_RETRY_COUNT | ||
|
||
num_fails = len(result.failures) | ||
num_errors = len(result.errors) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these part of the non-parallel test runner too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, these are part of the default unittest.py |
||
|
||
while retries_left >= 0: | ||
super().run(result) | ||
|
||
# The test passed if it didn't accumulate an error. | ||
if len(result.failures) == num_fails and len(result.errors) == num_errors: | ||
return | ||
|
||
retries_left -= 1 | ||
if retries_left >= 0: | ||
if len(result.failures) != num_fails: | ||
err = result.failures.pop(-1) | ||
elif len(result.errors) != num_errors: | ||
err = result.errors.pop(-1) | ||
else: | ||
raise Exception('Internal error in RetryableTestCase: did not detect an error') | ||
|
||
common.record_flaky_test(self.id(), EMTEST_RETRY_COUNT - retries_left, EMTEST_RETRY_COUNT, str(err)) |
Uh oh!
There was an error while loading. Please reload this page.