Skip to content

Commit 2d77018

Browse files
committed
Improve coverage for _report_unserialization_failure
1 parent ceef0af commit 2d77018

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/_pytest/reports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pprint import pprint
2+
13
import py
24
import six
35

@@ -258,8 +260,6 @@ def _from_json(cls, reportdict):
258260

259261

260262
def _report_unserialization_failure(type_name, report_class, reportdict):
261-
from pprint import pprint
262-
263263
url = "https://github.com/pytest-dev/pytest/issues"
264264
stream = py.io.TextIO()
265265
pprint("-" * 100, stream=stream)

testing/test_reports.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from _pytest.pathlib import Path
23
from _pytest.reports import CollectReport
34
from _pytest.reports import TestReport
@@ -219,6 +220,28 @@ def test_a():
219220
assert data["path1"] == str(testdir.tmpdir)
220221
assert data["path2"] == str(testdir.tmpdir)
221222

223+
def test_unserialization_failure(self, testdir):
224+
"""Check handling of failure during unserialization of report types."""
225+
testdir.makepyfile(
226+
"""
227+
def test_a():
228+
assert False
229+
"""
230+
)
231+
reprec = testdir.inline_run()
232+
reports = reprec.getreports("pytest_runtest_logreport")
233+
assert len(reports) == 3
234+
test_a_call = reports[1]
235+
data = test_a_call._to_json()
236+
entry = data["longrepr"]["reprtraceback"]["reprentries"][0]
237+
assert entry["type"] == "ReprEntry"
238+
239+
entry["type"] = "Unknown"
240+
with pytest.raises(
241+
RuntimeError, match="INTERNALERROR: Unknown entry type returned: Unknown"
242+
):
243+
TestReport._from_json(data)
244+
222245

223246
class TestHooks:
224247
"""Test that the hooks are working correctly for plugins"""

0 commit comments

Comments
 (0)