Merge pull request #7574 from nicoddemus/backport-7561
[6.0.x] Merge pull request #7561 from nicoddemus/longreprtext-7559
This commit is contained in:
commit
e8761576cd
|
@ -0,0 +1 @@
|
||||||
|
Fix regression in plugins using ``TestReport.longreprtext`` (such as ``pytest-html``) when ``TestReport.longrepr`` is not a string.
|
|
@ -82,9 +82,10 @@ class BaseReport:
|
||||||
longrepr.toterminal(out)
|
longrepr.toterminal(out)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
out.line(longrepr)
|
s = str(longrepr)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
out.line("<unprintable longrepr>")
|
s = "<unprintable longrepr>"
|
||||||
|
out.line(s)
|
||||||
|
|
||||||
def get_sections(self, prefix: str) -> Iterator[Tuple[str, str]]:
|
def get_sections(self, prefix: str) -> Iterator[Tuple[str, str]]:
|
||||||
for name, content in self.sections:
|
for name, content in self.sections:
|
||||||
|
|
|
@ -951,6 +951,33 @@ class TestReportContents:
|
||||||
rep = reports[1]
|
rep = reports[1]
|
||||||
assert rep.longreprtext == ""
|
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_collect_skip(self, testdir) -> None:
|
||||||
|
"""CollectReport.longreprtext can handle non-str ``longrepr`` attributes (#7559)"""
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
pytest.skip(allow_module_level=True)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
rec = testdir.inline_run()
|
||||||
|
calls = rec.getcalls("pytest_collectreport")
|
||||||
|
_, call = calls
|
||||||
|
assert isinstance(call.report.longrepr, tuple)
|
||||||
|
assert "Skipped" in call.report.longreprtext
|
||||||
|
|
||||||
def test_longreprtext_failure(self, testdir) -> None:
|
def test_longreprtext_failure(self, testdir) -> None:
|
||||||
reports = testdir.runitem(
|
reports = testdir.runitem(
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue