Skip to content

Commit

Permalink
Fix Issue #239 (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
metheuspsc authored Nov 22, 2023
1 parent 1069ae5 commit 1765772
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
17 changes: 8 additions & 9 deletions pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
else:
import importlib_metadata


try:
from xdist.newhooks import pytest_handlecrashitem

Expand All @@ -29,7 +28,6 @@
except ImportError:
HAS_PYTEST_HANDLECRASHITEM = False


PYTEST_GTE_63 = parse_version(pytest.__version__) >= parse_version("6.3.0")


Expand Down Expand Up @@ -266,6 +264,14 @@ def _get_rerun_filter_regex(item, regex_name):


def _matches_any_rerun_error(rerun_errors, report):
return _try_match_reprcrash(rerun_errors, report)


def _matches_any_rerun_except_error(rerun_except_errors, report):
return _try_match_reprcrash(rerun_except_errors, report)


def _try_match_reprcrash(rerun_errors, report):
for rerun_regex in rerun_errors:
try:
if re.search(rerun_regex, report.longrepr.reprcrash.message):
Expand All @@ -276,13 +282,6 @@ def _matches_any_rerun_error(rerun_errors, report):
return False


def _matches_any_rerun_except_error(rerun_except_errors, report):
for rerun_regex in rerun_except_errors:
if re.search(rerun_regex, report.longrepr.reprcrash.message):
return True
return False


def _should_hard_fail_on_error(item, report):
if report.outcome != "failed":
return False
Expand Down
32 changes: 18 additions & 14 deletions test_pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from pytest_rerunfailures import HAS_PYTEST_HANDLECRASHITEM


pytest_plugins = "pytester"

has_xdist = HAS_PYTEST_HANDLECRASHITEM
Expand Down Expand Up @@ -717,31 +716,36 @@ def test_fail():


@pytest.mark.parametrize(
"marker_rerun_except,cli_rerun_except,should_rerun",
"marker_rerun_except,cli_rerun_except,raised_error,should_rerun",
[
("AssertionError", None, False),
("AssertionError: ERR", None, False),
(["AssertionError"], None, False),
(["AssertionError: ABC"], None, True),
("ValueError", None, True),
(["ValueError"], None, True),
(["OSError", "ValueError"], None, True),
(["OSError", "AssertionError"], None, False),
("AssertionError", None, "AssertionError", False),
("AssertionError: ERR", None, "AssertionError", False),
(["AssertionError"], None, "AssertionError", False),
(["AssertionError: ABC"], None, "AssertionError", True),
("ValueError", None, "AssertionError", True),
(["ValueError"], None, "AssertionError", True),
(["OSError", "ValueError"], None, "AssertionError", True),
(["OSError", "AssertionError"], None, "AssertionError", False),
# CLI override behavior
("AssertionError", "ValueError", False),
("ValueError", "AssertionError", True),
("AssertionError", "ValueError", "AssertionError", False),
("ValueError", "AssertionError", "AssertionError", True),
("CustomFailure", None, "CustomFailure", False),
("CustomFailure", None, "AssertionError", True),
],
)
def test_rerun_except_flag_in_flaky_marker(
testdir, marker_rerun_except, cli_rerun_except, should_rerun
testdir, marker_rerun_except, cli_rerun_except, raised_error, should_rerun
):
testdir.makepyfile(
f"""
import pytest
class CustomFailure(Exception):
pass
@pytest.mark.flaky(reruns=1, rerun_except={marker_rerun_except!r})
def test_fail():
raise AssertionError("ERR")
raise {raised_error}("ERR")
"""
)
args = []
Expand Down

0 comments on commit 1765772

Please sign in to comment.