From f9ab81a4931f71740aecfd14e97b3187c7a1c37c Mon Sep 17 00:00:00 2001 From: Denis Otkidach Date: Wed, 26 Sep 2018 11:55:39 +0300 Subject: [PATCH 1/3] Exclude empty reports for passed tests --- src/_pytest/terminal.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 49a9a33fb..125eb97c4 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -745,9 +745,10 @@ class TerminalReporter(object): return self.write_sep("=", "PASSES") for rep in reports: - msg = self._getfailureheadline(rep) - self.write_sep("_", msg) - self._outrep_summary(rep) + if rep.sections: + msg = self._getfailureheadline(rep) + self.write_sep("_", msg) + self._outrep_summary(rep) def print_teardown_sections(self, rep): showcapture = self.config.option.showcapture From 808df48ee832c55840a58d81de8a52d7e1eb7ece Mon Sep 17 00:00:00 2001 From: Denis Otkidach Date: Wed, 26 Sep 2018 16:44:00 +0300 Subject: [PATCH 2/3] Test for excluding empty reports for passed tests --- testing/test_terminal.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index cca704c4c..7651f3ab3 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -681,14 +681,22 @@ def test_pass_reporting_on_fail(testdir): def test_pass_output_reporting(testdir): testdir.makepyfile( """ - def test_pass_output(): + def test_pass_has_output(): print("Four score and seven years ago...") + def test_pass_no_output(): + pass """ ) result = testdir.runpytest() - assert "Four score and seven years ago..." not in result.stdout.str() + s = result.stdout.str() + assert "test_pass_has_output" not in s + assert "Four score and seven years ago..." not in s + assert "test_pass_no_output" not in s result = testdir.runpytest("-rP") - result.stdout.fnmatch_lines(["Four score and seven years ago..."]) + result.stdout.fnmatch_lines( + ["*test_pass_has_output*", "Four score and seven years ago..."] + ) + assert "test_pass_no_output" not in result.stdout.str() def test_color_yes(testdir): From 44d29d887efb2993f7ffdd6b5615562223f44c01 Mon Sep 17 00:00:00 2001 From: Denis Otkidach Date: Wed, 26 Sep 2018 19:02:35 +0300 Subject: [PATCH 3/3] Changelog entry on excluding empty reports for passed tests --- changelog/4040.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/4040.trivial.rst diff --git a/changelog/4040.trivial.rst b/changelog/4040.trivial.rst new file mode 100644 index 000000000..d63541100 --- /dev/null +++ b/changelog/4040.trivial.rst @@ -0,0 +1 @@ +Exclude empty reports for passed tests when ``-rP`` option is used.