From 0ab85e7a9cfc6f36a37a6e79dbb73b2b83c997bc Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Mon, 10 Apr 2017 17:42:19 +0900 Subject: [PATCH 1/3] 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 0b8e71a71ab..4cecc771d96 100755 --- a/_pytest/cacheprovider.py +++ b/_pytest/cacheprovider.py @@ -139,11 +139,11 @@ def pytest_collection_modifyitems(self, session, config, items): # 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 f5904be39d6..67237159637 100755 --- a/testing/test_cache.py +++ b/testing/test_cache.py @@ -192,13 +192,34 @@ def test_always_fails(): "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=""" From 08d83a5c6a7c74cd00d21887731ad26a4412d7fd Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Mon, 10 Apr 2017 17:50:18 +0900 Subject: [PATCH 2/3] updated changelog and authors files --- AUTHORS | 1 + CHANGELOG.rst | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/AUTHORS b/AUTHORS index 3d59906b230..3d7f10d5e56 100644 --- a/AUTHORS +++ b/AUTHORS @@ -78,6 +78,7 @@ Javier Romero Jeff Widman John Towler Jon Sonesen +Jonas Obrist Jordan Guymon Joshua Bronson Jurko Gospodnetić diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6eae9b1d1a2..ea758a31709 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -69,6 +69,9 @@ Changes * ``PluginManager.import_plugin`` now accepts unicode plugin names in Python 2. Thanks `@reutsharabani`_ for the PR. +* fix `#2308`_: When using both ``--lf`` and ``--ff``, only the last failed tests are run. + Thanks `@ojii`_ for the PR. + Bug Fixes --------- @@ -88,6 +91,7 @@ Bug Fixes .. _@reutsharabani: https://github.com/reutsharabani .. _@unsignedint: https://github.com/unsignedint .. _@Kriechi: https://github.com/Kriechi +.. _@ojii: https://github.com/ojii .. _#1407: https://github.com/pytest-dev/pytest/issues/1407 @@ -101,6 +105,7 @@ Bug Fixes .. _#2147: https://github.com/pytest-dev/pytest/issues/2147 .. _#2208: https://github.com/pytest-dev/pytest/issues/2208 .. _#2228: https://github.com/pytest-dev/pytest/issues/2228 +.. _#2308: https://github.com/pytest-dev/pytest/issues/2308 3.0.8 (unreleased) From 1125786e787b320dd26d8c720c6ce81c72a1c838 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 11 Apr 2017 17:55:55 -0300 Subject: [PATCH 3/3] Improve --lf/--ff test as commented during review --- testing/test_cache.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/testing/test_cache.py b/testing/test_cache.py index 67237159637..600b5e6d9fc 100755 --- a/testing/test_cache.py +++ b/testing/test_cache.py @@ -200,14 +200,16 @@ def test_always_fails(): ]) 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 - """)) + testdir.makepyfile(**{ + 'test_a.py': """ + def test_always_passes(): + assert 1 + """, + 'test_b.py': """ + def test_always_fails(): + assert 0 + """, + }) result = testdir.runpytest() # Test order will be collection order; alphabetical result.stdout.fnmatch_lines([ @@ -219,6 +221,7 @@ def test_always_fails(): result.stdout.fnmatch_lines([ "test_b.py*", ]) + assert 'test_a.py' not in result.stdout.str() def test_lastfailed_difference_invocations(self, testdir, monkeypatch): monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)