Skip to content

Commit bf3b26b

Browse files
committed
Fix regression with --lf and non-selected failures
1 parent 5c5966f commit bf3b26b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/_pytest/cacheprovider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def pytest_ignore_collect(self, path):
178178
"""
179179
if (
180180
self.active
181+
and self._previously_failed_count
181182
and self.config.getoption("lf")
182183
and path.isfile()
183184
and self.lastfailed

testing/test_cacheprovider.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,26 @@ def test_3(): pass
832832
]
833833
)
834834

835+
def test_lastfailed_with_unknown_failure(self, testdir):
836+
testdir.makepyfile(
837+
**{
838+
"pkg1/test_1.py": """def test_1(): assert 0""",
839+
"pkg1/test_2.py": """def test_2(): pass""",
840+
}
841+
)
842+
result = testdir.runpytest()
843+
result.stdout.fnmatch_lines(["collected 2 items", "* 1 failed, 1 passed in *"])
844+
845+
py.path.local("pkg1/test_1.py").remove()
846+
result = testdir.runpytest("--lf")
847+
result.stdout.fnmatch_lines(
848+
[
849+
"collected 1 item",
850+
"run-last-failure: 1 known failures not in selected tests",
851+
"* 1 passed in *",
852+
]
853+
)
854+
835855

836856
class TestNewFirst(object):
837857
def test_newfirst_usecase(self, testdir):

0 commit comments

Comments
 (0)