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.
This commit is contained in:
parent
83b241b449
commit
0ab85e7a9c
|
@ -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
|
||||
|
|
|
@ -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="""
|
||||
|
|
Loading…
Reference in New Issue