From d46ecbc18b74b895b71e257bf07836cd2cfae89e Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 15 Dec 2020 20:16:28 +0200 Subject: [PATCH] terminal: fix "()" skip reason in test status line --- changelog/8152.bugfix.rst | 1 + src/_pytest/outcomes.py | 2 +- src/_pytest/terminal.py | 2 ++ testing/test_terminal.py | 26 ++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 changelog/8152.bugfix.rst diff --git a/changelog/8152.bugfix.rst b/changelog/8152.bugfix.rst new file mode 100644 index 00000000000..d79a832de41 --- /dev/null +++ b/changelog/8152.bugfix.rst @@ -0,0 +1 @@ +Fixed "()" being shown as a skip reason in the verbose test summary line when the reason is empty. diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index f0607cbd849..8f6203fd7fa 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -38,7 +38,7 @@ def __init__(self, msg: Optional[str] = None, pytrace: bool = True) -> None: self.pytrace = pytrace def __repr__(self) -> str: - if self.msg: + if self.msg is not None: return self.msg return f"<{self.__class__.__name__} instance>" diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 39adfaaa310..f5d4e1f8ddc 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -1403,4 +1403,6 @@ def _get_raw_skip_reason(report: TestReport) -> str: _, _, reason = report.longrepr if reason.startswith("Skipped: "): reason = reason[len("Skipped: ") :] + elif reason == "Skipped": + reason = "" return reason diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 6319188a75e..6d0a23fe0f1 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -366,6 +366,26 @@ def test_3(): @pytest.mark.xfail(reason="") def test_4(): assert False + + @pytest.mark.skip + def test_5(): + pass + + @pytest.mark.xfail + def test_6(): + pass + + def test_7(): + pytest.skip() + + def test_8(): + pytest.skip("888 is great") + + def test_9(): + pytest.xfail() + + def test_10(): + pytest.xfail("It's 🕙 o'clock") """ ) result = pytester.runpytest("-v") @@ -375,6 +395,12 @@ def test_4(): "test_verbose_skip_reason.py::test_2 XPASS (456) *", "test_verbose_skip_reason.py::test_3 XFAIL (789) *", "test_verbose_skip_reason.py::test_4 XFAIL *", + "test_verbose_skip_reason.py::test_5 SKIPPED (unconditional skip) *", + "test_verbose_skip_reason.py::test_6 XPASS *", + "test_verbose_skip_reason.py::test_7 SKIPPED *", + "test_verbose_skip_reason.py::test_8 SKIPPED (888 is great) *", + "test_verbose_skip_reason.py::test_9 XFAIL *", + "test_verbose_skip_reason.py::test_10 XFAIL (It's 🕙 o'clock) *", ] )