Skip to content

Commit 2b862b3

Browse files
Mal-labMichael Howitz
authored andcommitted
Fix crash with strict xfail and --only-rerun flag
1 parent 121ce30 commit 2b862b3

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Bug fixes
1010
- Fix crash when pytest-xdist is installed but disabled.
1111
(Thanks to `@mgorny <https://github.com/mgorny>`_ for the PR.)
1212

13+
- Fix crash when xfail(strict=True) mark is used with --rerun-only flag.
14+
1315
Features
1416
++++++++
1517

pytest_rerunfailures.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,12 @@ def _should_hard_fail_on_error(session_config, report):
298298

299299
if rerun_errors:
300300
for rerun_regex in rerun_errors:
301-
if re.search(rerun_regex, report.longrepr.reprcrash.message):
302-
303-
return False
301+
try:
302+
if re.search(rerun_regex, report.longrepr.reprcrash.message):
303+
return False
304+
except AttributeError:
305+
if re.search(rerun_regex, report.longreprtext):
306+
return False
304307

305308
if rerun_except_errors:
306309
for rerun_regex in rerun_except_errors:

test_pytest_rerunfailures.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,19 @@ def test_only_rerun_flag(testdir, only_rerun_texts, should_rerun):
552552
)
553553

554554

555+
def test_no_rerun_on_strict_xfail_with_only_rerun_flag(testdir):
556+
testdir.makepyfile(
557+
"""
558+
import pytest
559+
@pytest.mark.xfail(strict=True)
560+
def test_xfail():
561+
assert True
562+
"""
563+
)
564+
result = testdir.runpytest("--reruns", "1", "--only-rerun", "RuntimeError")
565+
assert_outcomes(result, passed=0, failed=1, rerun=0)
566+
567+
555568
@pytest.mark.parametrize(
556569
"rerun_except_texts, should_rerun",
557570
[

0 commit comments

Comments
 (0)