Skip to content

Commit

Permalink
Improve coverage for _report_unserialization_failure
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Mar 25, 2019
1 parent ceef0af commit 2d77018
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/_pytest/reports.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pprint import pprint

import py
import six

Expand Down Expand Up @@ -258,8 +260,6 @@ def _from_json(cls, reportdict):


def _report_unserialization_failure(type_name, report_class, reportdict):
from pprint import pprint

url = "https://github.com/pytest-dev/pytest/issues"
stream = py.io.TextIO()
pprint("-" * 100, stream=stream)
Expand Down
23 changes: 23 additions & 0 deletions testing/test_reports.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from _pytest.pathlib import Path
from _pytest.reports import CollectReport
from _pytest.reports import TestReport
Expand Down Expand Up @@ -219,6 +220,28 @@ def test_a():
assert data["path1"] == str(testdir.tmpdir)
assert data["path2"] == str(testdir.tmpdir)

def test_unserialization_failure(self, testdir):
"""Check handling of failure during unserialization of report types."""
testdir.makepyfile(
"""
def test_a():
assert False
"""
)
reprec = testdir.inline_run()
reports = reprec.getreports("pytest_runtest_logreport")
assert len(reports) == 3
test_a_call = reports[1]
data = test_a_call._to_json()
entry = data["longrepr"]["reprtraceback"]["reprentries"][0]
assert entry["type"] == "ReprEntry"

entry["type"] = "Unknown"
with pytest.raises(
RuntimeError, match="INTERNALERROR: Unknown entry type returned: Unknown"
):
TestReport._from_json(data)


class TestHooks:
"""Test that the hooks are working correctly for plugins"""
Expand Down

0 comments on commit 2d77018

Please sign in to comment.