Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminal: fix "(<Skipped instance>)" skip reason in test status line #8152

Merged
merged 1 commit into from Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/8152.bugfix.rst
@@ -0,0 +1 @@
Fixed "(<Skipped instance>)" being shown as a skip reason in the verbose test summary line when the reason is empty.
2 changes: 1 addition & 1 deletion src/_pytest/outcomes.py
Expand Up @@ -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:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behavior of str(Skipped("")). But if an empty string is explicitly passed I think it makes sense that the str() is empty.

return self.msg
return f"<{self.__class__.__name__} instance>"

Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/terminal.py
Expand Up @@ -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
26 changes: 26 additions & 0 deletions testing/test_terminal.py
Expand Up @@ -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")
Expand All @@ -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) *",
]
)

Expand Down