Skip to content

Commit

Permalink
xfail and skipped tests are removed from the "last-failed" cache
Browse files Browse the repository at this point in the history
This accommodates the case where a failing test is marked as
skipped/failed later
  • Loading branch information
nicoddemus committed Jul 27, 2017
1 parent 22212c4 commit eb1bd34
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def pytest_report_header(self):
return "run-last-failure: %s" % mode

def pytest_runtest_logreport(self, report):
if report.passed and report.when == 'call':
if (report.when == 'call' and report.passed) or report.skipped:
self.lastfailed.pop(report.nodeid, None)
elif report.failed:
self.lastfailed[report.nodeid] = True
Expand Down
22 changes: 22 additions & 0 deletions testing/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,28 @@ def test():
result.stdout.fnmatch_lines('*1 failed*')
assert self.get_cached_last_failed(testdir) == ['test_xfail_strict_considered_failure.py::test']

@pytest.mark.parametrize('mark', ['mark.xfail', 'mark.skip'])
def test_failed_changed_to_xfail_or_skip(self, testdir, mark):
testdir.makepyfile('''
import pytest
def test():
assert 0
''')
result = testdir.runpytest()
assert self.get_cached_last_failed(testdir) == ['test_failed_changed_to_xfail_or_skip.py::test']
assert result.ret == 1

testdir.makepyfile('''
import pytest
@pytest.{mark}
def test():
assert 0
'''.format(mark=mark))
result = testdir.runpytest()
assert result.ret == 0
assert self.get_cached_last_failed(testdir) == []
assert result.ret == 0

def get_cached_last_failed(self, testdir):
config = testdir.parseconfigure()
return sorted(config.cache.get("cache/lastfailed", {}))
Expand Down

0 comments on commit eb1bd34

Please sign in to comment.