Skip to content

Commit

Permalink
Fix TestReport.longreprtext when TestReport.longrepr is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jul 29, 2020
1 parent df09a31 commit c587089
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/7559.bugfix.rst
@@ -0,0 +1 @@
Fix regression in plugins using ``TestReport.longreprtext`` (such as ``pytest-html``) when ``TestReport.longrepr`` is not a string.
5 changes: 3 additions & 2 deletions src/_pytest/reports.py
Expand Up @@ -82,9 +82,10 @@ def toterminal(self, out: TerminalWriter) -> None:
longrepr.toterminal(out)
else:
try:
out.line(longrepr)
s = str(longrepr)
except UnicodeEncodeError:
out.line("<unprintable longrepr>")
s = "<unprintable longrepr>"
out.line(s)

def get_sections(self, prefix: str) -> Iterator[Tuple[str, str]]:
for name, content in self.sections:
Expand Down
13 changes: 13 additions & 0 deletions testing/test_runner.py
Expand Up @@ -951,6 +951,19 @@ def test_func():
rep = reports[1]
assert rep.longreprtext == ""

def test_longreprtext_skip(self, testdir) -> None:
"""TestReport.longreprtext can handle non-str ``longrepr`` attributes (#7559)"""
reports = testdir.runitem(
"""
import pytest
def test_func():
pytest.skip()
"""
)
_, call_rep, _ = reports
assert isinstance(call_rep.longrepr, tuple)
assert "Skipped" in call_rep.longreprtext

def test_longreprtext_failure(self, testdir) -> None:
reports = testdir.runitem(
"""
Expand Down

0 comments on commit c587089

Please sign in to comment.