From 0ab85e7a9cfc6f36a37a6e79dbb73b2b83c997bc Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Mon, 10 Apr 2017 17:42:19 +0900 Subject: [PATCH] Changed behavior if --lf and --ff are both used. When using both --last-failed/--lf and --failed-first/--ff pytest would run all tests with failed tests first (as if --lf was not provied). This patch changes it so that when using both flags, only the last failed tests are run. This makes it easier to set --ff as the default behavior via the config file and then selectively use --lf to only run the last failed tests. --- _pytest/cacheprovider.py | 6 +++--- testing/test_cache.py | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) 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="""