-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
|
||
|
||
@pytest.hookimpl(tryfirst=True, hookwrapper=True) | ||
def pytest_runtest_makereport(item, call): | ||
outcome = yield | ||
report = outcome.get_result() | ||
|
||
if report.when == 'call' and report.failed and call.excinfo is not None: | ||
if call.excinfo is not None: | ||
exc_value = call.excinfo.value | ||
error_message = str(exc_value) | ||
if '502' in error_message or 'Read timed out' in error_message: | ||
setattr(report, 'wasxfail', False) | ||
setattr(report, 'rerun', True) | ||
report.outcome = 'failed' | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption('--n_reruns', action='store', default=5, help='Number of times to rerun failed tests') | ||
|
||
|
||
@pytest.hookimpl(tryfirst=True, hookwrapper=True) | ||
def pytest_runtest_protocol(item, nextitem): | ||
try: | ||
reruns = int(item.config.getoption('--n_reruns')) | ||
except TypeError: | ||
reruns = 0 | ||
for i in range(reruns + 1): | ||
if i > 0: | ||
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location) | ||
outcome = yield | ||
report = outcome.get_result() | ||
if not getattr(report, 'rerun', False): | ||
break | ||
if i == reruns: | ||
report.outcome = 'failed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters