Skip to content

Commit

Permalink
Merge pull request #3912 from dhirensr/needless_message
Browse files Browse the repository at this point in the history
Needless message printed with --failed-first and no failed tests #3853
  • Loading branch information
nicoddemus authored Aug 30, 2018
2 parents a605ad4 + 84a033f commit 64f0068
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Christian Theunert
Christian Tismer
Christopher Gilling
Cyrus Maden
Dhiren Serai
Daniel Grana
Daniel Hahler
Daniel Nuri
Expand Down
1 change: 1 addition & 0 deletions changelog/3853.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed ``"run all (no recorded failures)"`` message printed with ``--failed-first`` and ``--last-failed`` when there are no failed tests.
15 changes: 6 additions & 9 deletions src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,12 @@ def __init__(self, config):
def pytest_report_collectionfinish(self):
if self.active:
if not self._previously_failed_count:
mode = "run {} (no recorded failures)".format(
self._no_failures_behavior
)
else:
noun = "failure" if self._previously_failed_count == 1 else "failures"
suffix = " first" if self.config.getoption("failedfirst") else ""
mode = "rerun previous {count} {noun}{suffix}".format(
count=self._previously_failed_count, suffix=suffix, noun=noun
)
return None
noun = "failure" if self._previously_failed_count == 1 else "failures"
suffix = " first" if self.config.getoption("failedfirst") else ""
mode = "rerun previous {count} {noun}{suffix}".format(
count=self._previously_failed_count, suffix=suffix, noun=noun
)
return "run-last-failure: %s" % mode

def pytest_runtest_logreport(self, report):
Expand Down
19 changes: 12 additions & 7 deletions testing/test_cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,7 @@ def test_b2():
)

result = testdir.runpytest(test_a, "--lf")
result.stdout.fnmatch_lines(
[
"collected 2 items",
"run-last-failure: run all (no recorded failures)",
"*2 passed in*",
]
)
result.stdout.fnmatch_lines(["collected 2 items", "*2 passed in*"])

result = testdir.runpytest(test_b, "--lf")
result.stdout.fnmatch_lines(
Expand Down Expand Up @@ -617,6 +611,17 @@ def test():
assert self.get_cached_last_failed(testdir) == []
assert result.ret == 0

@pytest.mark.parametrize("quiet", [True, False])
@pytest.mark.parametrize("opt", ["--ff", "--lf"])
def test_lf_and_ff_prints_no_needless_message(self, quiet, opt, testdir):
# Issue 3853
testdir.makepyfile("def test(): pass")
args = [opt]
if quiet:
args.append("-q")
result = testdir.runpytest(*args)
assert "run all" not in result.stdout.str()

def get_cached_last_failed(self, testdir):
config = testdir.parseconfigure()
return sorted(config.cache.get("cache/lastfailed", {}))
Expand Down

0 comments on commit 64f0068

Please sign in to comment.