Skip to content

Commit

Permalink
fixup! Fix regression with --lf and non-selected failures
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed May 29, 2019
1 parent bf3b26b commit ceb4f3f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog/5333.bugfix.rst
@@ -0,0 +1 @@
Fix regression with ``--lf`` not re-running all tests with known failures from non-selected tests.
19 changes: 8 additions & 11 deletions src/_pytest/cacheprovider.py
Expand Up @@ -168,6 +168,7 @@ def last_failed_paths(self):
if result is None:
rootpath = Path(self.config.rootdir)
result = {rootpath / nodeid.split("::")[0] for nodeid in self.lastfailed}
result = {x for x in result if x.exists()}
self._last_failed_paths = result
return result

Expand All @@ -176,17 +177,13 @@ def pytest_ignore_collect(self, path):
Ignore this file path if we are in --lf mode and it is not in the list of
previously failed files.
"""
if (
self.active
and self._previously_failed_count
and self.config.getoption("lf")
and path.isfile()
and self.lastfailed
):
skip_it = Path(path) not in self.last_failed_paths()
if skip_it:
self._skipped_files += 1
return skip_it
if self.active and self.config.getoption("lf") and path.isfile():
last_failed_paths = self.last_failed_paths()
if last_failed_paths:
skip_it = Path(path) not in self.last_failed_paths()
if skip_it:
self._skipped_files += 1
return skip_it

def pytest_report_collectionfinish(self):
if self.active and self.config.getoption("verbose") >= 0:
Expand Down
24 changes: 23 additions & 1 deletion testing/test_cacheprovider.py
Expand Up @@ -832,7 +832,7 @@ def test_3(): pass
]
)

def test_lastfailed_with_unknown_failure(self, testdir):
def test_lastfailed_with_known_failures_not_being_selected(self, testdir):
testdir.makepyfile(
**{
"pkg1/test_1.py": """def test_1(): assert 0""",
Expand All @@ -852,6 +852,28 @@ def test_lastfailed_with_unknown_failure(self, testdir):
]
)

# Recreate file with known failure.
testdir.makepyfile(**{"pkg1/test_1.py": """def test_1(): assert 0"""})
result = testdir.runpytest("--lf")
result.stdout.fnmatch_lines(
[
"collected 1 item",
"run-last-failure: rerun previous 1 failure (skipped 1 file)",
"* 1 failed in *",
]
)

# Remove/rename test.
testdir.makepyfile(**{"pkg1/test_1.py": """def test_renamed(): assert 0"""})
result = testdir.runpytest("--lf")
result.stdout.fnmatch_lines(
[
"collected 1 item",
"run-last-failure: 1 known failures not in selected tests",
"* 1 failed in *",
]
)


class TestNewFirst(object):
def test_newfirst_usecase(self, testdir):
Expand Down

0 comments on commit ceb4f3f

Please sign in to comment.