Skip to content

Commit 1765772

Browse files
authored
Fix Issue #239 (#240)
1 parent 1069ae5 commit 1765772

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

pytest_rerunfailures.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
else:
2121
import importlib_metadata
2222

23-
2423
try:
2524
from xdist.newhooks import pytest_handlecrashitem
2625

@@ -29,7 +28,6 @@
2928
except ImportError:
3029
HAS_PYTEST_HANDLECRASHITEM = False
3130

32-
3331
PYTEST_GTE_63 = parse_version(pytest.__version__) >= parse_version("6.3.0")
3432

3533

@@ -266,6 +264,14 @@ def _get_rerun_filter_regex(item, regex_name):
266264

267265

268266
def _matches_any_rerun_error(rerun_errors, report):
267+
return _try_match_reprcrash(rerun_errors, report)
268+
269+
270+
def _matches_any_rerun_except_error(rerun_except_errors, report):
271+
return _try_match_reprcrash(rerun_except_errors, report)
272+
273+
274+
def _try_match_reprcrash(rerun_errors, report):
269275
for rerun_regex in rerun_errors:
270276
try:
271277
if re.search(rerun_regex, report.longrepr.reprcrash.message):
@@ -276,13 +282,6 @@ def _matches_any_rerun_error(rerun_errors, report):
276282
return False
277283

278284

279-
def _matches_any_rerun_except_error(rerun_except_errors, report):
280-
for rerun_regex in rerun_except_errors:
281-
if re.search(rerun_regex, report.longrepr.reprcrash.message):
282-
return True
283-
return False
284-
285-
286285
def _should_hard_fail_on_error(item, report):
287286
if report.outcome != "failed":
288287
return False

test_pytest_rerunfailures.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from pytest_rerunfailures import HAS_PYTEST_HANDLECRASHITEM
88

9-
109
pytest_plugins = "pytester"
1110

1211
has_xdist = HAS_PYTEST_HANDLECRASHITEM
@@ -717,31 +716,36 @@ def test_fail():
717716

718717

719718
@pytest.mark.parametrize(
720-
"marker_rerun_except,cli_rerun_except,should_rerun",
719+
"marker_rerun_except,cli_rerun_except,raised_error,should_rerun",
721720
[
722-
("AssertionError", None, False),
723-
("AssertionError: ERR", None, False),
724-
(["AssertionError"], None, False),
725-
(["AssertionError: ABC"], None, True),
726-
("ValueError", None, True),
727-
(["ValueError"], None, True),
728-
(["OSError", "ValueError"], None, True),
729-
(["OSError", "AssertionError"], None, False),
721+
("AssertionError", None, "AssertionError", False),
722+
("AssertionError: ERR", None, "AssertionError", False),
723+
(["AssertionError"], None, "AssertionError", False),
724+
(["AssertionError: ABC"], None, "AssertionError", True),
725+
("ValueError", None, "AssertionError", True),
726+
(["ValueError"], None, "AssertionError", True),
727+
(["OSError", "ValueError"], None, "AssertionError", True),
728+
(["OSError", "AssertionError"], None, "AssertionError", False),
730729
# CLI override behavior
731-
("AssertionError", "ValueError", False),
732-
("ValueError", "AssertionError", True),
730+
("AssertionError", "ValueError", "AssertionError", False),
731+
("ValueError", "AssertionError", "AssertionError", True),
732+
("CustomFailure", None, "CustomFailure", False),
733+
("CustomFailure", None, "AssertionError", True),
733734
],
734735
)
735736
def test_rerun_except_flag_in_flaky_marker(
736-
testdir, marker_rerun_except, cli_rerun_except, should_rerun
737+
testdir, marker_rerun_except, cli_rerun_except, raised_error, should_rerun
737738
):
738739
testdir.makepyfile(
739740
f"""
740741
import pytest
741742
743+
class CustomFailure(Exception):
744+
pass
745+
742746
@pytest.mark.flaky(reruns=1, rerun_except={marker_rerun_except!r})
743747
def test_fail():
744-
raise AssertionError("ERR")
748+
raise {raised_error}("ERR")
745749
"""
746750
)
747751
args = []

0 commit comments

Comments
 (0)