Skip to content

Commit eb1bd34

Browse files
committed
xfail and skipped tests are removed from the "last-failed" cache
This accommodates the case where a failing test is marked as skipped/failed later
1 parent 22212c4 commit eb1bd34

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

_pytest/cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def pytest_report_header(self):
117117
return "run-last-failure: %s" % mode
118118

119119
def pytest_runtest_logreport(self, report):
120-
if report.passed and report.when == 'call':
120+
if (report.when == 'call' and report.passed) or report.skipped:
121121
self.lastfailed.pop(report.nodeid, None)
122122
elif report.failed:
123123
self.lastfailed[report.nodeid] = True

testing/test_cache.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,28 @@ def test():
460460
result.stdout.fnmatch_lines('*1 failed*')
461461
assert self.get_cached_last_failed(testdir) == ['test_xfail_strict_considered_failure.py::test']
462462

463+
@pytest.mark.parametrize('mark', ['mark.xfail', 'mark.skip'])
464+
def test_failed_changed_to_xfail_or_skip(self, testdir, mark):
465+
testdir.makepyfile('''
466+
import pytest
467+
def test():
468+
assert 0
469+
''')
470+
result = testdir.runpytest()
471+
assert self.get_cached_last_failed(testdir) == ['test_failed_changed_to_xfail_or_skip.py::test']
472+
assert result.ret == 1
473+
474+
testdir.makepyfile('''
475+
import pytest
476+
@pytest.{mark}
477+
def test():
478+
assert 0
479+
'''.format(mark=mark))
480+
result = testdir.runpytest()
481+
assert result.ret == 0
482+
assert self.get_cached_last_failed(testdir) == []
483+
assert result.ret == 0
484+
463485
def get_cached_last_failed(self, testdir):
464486
config = testdir.parseconfigure()
465487
return sorted(config.cache.get("cache/lastfailed", {}))

0 commit comments

Comments
 (0)