From 59067ad33d55e66a54ec617effe4350e42d66f65 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 12 Dec 2019 07:41:23 -0300 Subject: [PATCH 1/3] Make -r letters "f" and "F" aliases As far as the output is concerned, they are both identical so it doesn't make sense to have both. setup, teardown, and collect failures are already reported as "errors", "E". --- src/_pytest/terminal.py | 13 ++++++------- testing/test_terminal.py | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index e88545eca..d1ee701e8 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -173,6 +173,9 @@ def getreportopt(config: Config) -> str: elif config.option.disable_warnings and "w" in reportchars: reportchars = reportchars.replace("w", "") for char in reportchars: + # f and F are aliases + if char == "F": + char = "f" if char == "a": reportopts = "sxXwEf" elif char == "A": @@ -185,19 +188,16 @@ def getreportopt(config: Config) -> str: @pytest.hookimpl(trylast=True) # after _pytest.runner def pytest_report_teststatus(report: TestReport) -> Tuple[str, str, str]: + letter = "F" if report.passed: letter = "." elif report.skipped: letter = "s" - elif report.failed: - letter = "F" - if report.when != "call": - letter = "f" - # Report failed CollectReports as "error" (in line with pytest_collectreport). outcome = report.outcome - if report.when == "collect" and outcome == "failed": + if report.when in ("collect", "setup", "teardown") and outcome == "failed": outcome = "error" + letter = "E" return outcome, letter, outcome.upper() @@ -988,7 +988,6 @@ class TerminalReporter: "x": show_xfailed, "X": show_xpassed, "f": partial(show_simple, "failed"), - "F": partial(show_simple, "failed"), "s": show_skipped, "S": show_skipped, "p": partial(show_simple, "passed"), diff --git a/testing/test_terminal.py b/testing/test_terminal.py index fab13b07e..2d875a64c 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -754,6 +754,18 @@ class TestTerminalFunctional: result = testdir.runpytest(*params) result.stdout.fnmatch_lines(["collected 3 items", "hello from hook: 3 items"]) + def test_summary_f_alias(self, testdir): + testdir.makepyfile( + """ + def test(): + assert False + """ + ) + result = testdir.runpytest("-rfF") + expected = "FAILED test_summary_f_alias.py::test - assert False" + result.stdout.fnmatch_lines([expected]) + assert result.stdout.lines.count(expected) == 1 + def test_fail_extra_reporting(testdir, monkeypatch): monkeypatch.setenv("COLUMNS", "80") @@ -1685,12 +1697,16 @@ class TestProgressWithTeardown: testdir.makepyfile( """ def test_foo(fail_teardown): - assert False + assert 0 """ ) - output = testdir.runpytest() + output = testdir.runpytest("-rfE") output.stdout.re_match_lines( - [r"test_teardown_with_test_also_failing.py FE\s+\[100%\]"] + [ + r"test_teardown_with_test_also_failing.py FE\s+\[100%\]", + "FAILED test_teardown_with_test_also_failing.py::test_foo - assert 0", + "ERROR test_teardown_with_test_also_failing.py::test_foo - assert False", + ] ) def test_teardown_many(self, testdir, many_files): From fa51a26743930576e2587a92217b1d9f5063175d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 12 Dec 2019 07:48:07 -0300 Subject: [PATCH 2/3] Make -r letters "s" and "S" aliases Similar reasons as the previous commit --- src/_pytest/terminal.py | 8 ++++---- testing/test_terminal.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index d1ee701e8..2a99bfdd5 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -172,10 +172,11 @@ def getreportopt(config: Config) -> str: reportchars += "w" elif config.option.disable_warnings and "w" in reportchars: reportchars = reportchars.replace("w", "") + aliases = {"F", "S"} for char in reportchars: - # f and F are aliases - if char == "F": - char = "f" + # handle old aliases + if char in aliases: + char = char.lower() if char == "a": reportopts = "sxXwEf" elif char == "A": @@ -989,7 +990,6 @@ class TerminalReporter: "X": show_xpassed, "f": partial(show_simple, "failed"), "s": show_skipped, - "S": show_skipped, "p": partial(show_simple, "passed"), "E": partial(show_simple, "error"), } # type: Mapping[str, Callable[[List[str]], None]] diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 2d875a64c..0fe0e09e1 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -755,6 +755,7 @@ class TestTerminalFunctional: result.stdout.fnmatch_lines(["collected 3 items", "hello from hook: 3 items"]) def test_summary_f_alias(self, testdir): + """Test that 'f' and 'F' report chars are aliases and don't show up twice in the summary (#6334)""" testdir.makepyfile( """ def test(): @@ -766,6 +767,22 @@ class TestTerminalFunctional: result.stdout.fnmatch_lines([expected]) assert result.stdout.lines.count(expected) == 1 + def test_summary_s_alias(self, testdir): + """Test that 's' and 'S' report chars are aliases and don't show up twice in the summary""" + testdir.makepyfile( + """ + import pytest + + @pytest.mark.skip + def test(): + pass + """ + ) + result = testdir.runpytest("-rsS") + expected = "SKIPPED [1] test_summary_s_alias.py:3: unconditional skip" + result.stdout.fnmatch_lines([expected]) + assert result.stdout.lines.count(expected) == 1 + def test_fail_extra_reporting(testdir, monkeypatch): monkeypatch.setenv("COLUMNS", "80") From 9b74bf1e0c4e0f3ce4e440ec50ca9b5f190ce8c7 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 12 Dec 2019 08:05:22 -0300 Subject: [PATCH 3/3] Add CHANGELOG entry for #6334 --- changelog/6334.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/6334.bugfix.rst diff --git a/changelog/6334.bugfix.rst b/changelog/6334.bugfix.rst new file mode 100644 index 000000000..abd4c748b --- /dev/null +++ b/changelog/6334.bugfix.rst @@ -0,0 +1,3 @@ +Fix summary entries appearing twice when ``f/F`` and ``s/S`` report chars were used at the same time in the ``-r`` command-line option (for example ``-rFf``). + +The upper case variants were never documented and the preferred form should be the lower case.