diff --git a/_pytest/cacheprovider.py b/_pytest/cacheprovider.py index 0b8e71a71..4cecc771d 100755 --- a/_pytest/cacheprovider.py +++ b/_pytest/cacheprovider.py @@ -139,11 +139,11 @@ class LFPlugin(object): # running a subset of all tests with recorded failures outside # of the set of tests currently executing pass - elif self.config.getvalue("failedfirst"): - items[:] = previously_failed + previously_passed - else: + elif self.config.getvalue("lf"): items[:] = previously_failed config.hook.pytest_deselected(items=previously_passed) + else: + items[:] = previously_failed + previously_passed def pytest_sessionfinish(self, session): config = self.config diff --git a/testing/test_cache.py b/testing/test_cache.py index f5904be39..672371596 100755 --- a/testing/test_cache.py +++ b/testing/test_cache.py @@ -192,13 +192,34 @@ class TestLastFailed(object): "test_a.py*", "test_b.py*", ]) - result = testdir.runpytest("--lf", "--ff") + result = testdir.runpytest("--ff") # Test order will be failing tests firs result.stdout.fnmatch_lines([ "test_b.py*", "test_a.py*", ]) + def test_lastfailed_failedfirst_order(self, testdir): + testdir.tmpdir.join('test_a.py').write(_pytest._code.Source(""" + def test_always_passes(): + assert 1 + """)) + testdir.tmpdir.join('test_b.py').write(_pytest._code.Source(""" + def test_always_fails(): + assert 0 + """)) + result = testdir.runpytest() + # Test order will be collection order; alphabetical + result.stdout.fnmatch_lines([ + "test_a.py*", + "test_b.py*", + ]) + result = testdir.runpytest("--lf", "--ff") + # Test order will be failing tests firs + result.stdout.fnmatch_lines([ + "test_b.py*", + ]) + def test_lastfailed_difference_invocations(self, testdir, monkeypatch): monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1) testdir.makepyfile(test_a="""