Merge pull request #2357 from ojii/lastfailed-failedfirst

Changed behavior if --lf and --ff are both used.
This commit is contained in:
Bruno Oliveira 2017-04-11 19:05:01 -03:00 committed by GitHub
commit 02da278894
4 changed files with 34 additions and 4 deletions

View File

@ -78,6 +78,7 @@ Javier Romero
Jeff Widman
John Towler
Jon Sonesen
Jonas Obrist
Jordan Guymon
Joshua Bronson
Jurko Gospodnetić

View File

@ -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)

View File

@ -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

View File

@ -192,13 +192,37 @@ 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.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([
"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*",
])
assert 'test_a.py' not in result.stdout.str()
def test_lastfailed_difference_invocations(self, testdir, monkeypatch):
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)
testdir.makepyfile(test_a="""