Fix assertion in pytest_report_unserialize

This commit is contained in:
Bruno Oliveira 2019-03-26 12:47:31 -03:00
parent 2d77018d1b
commit 9311d822c7
2 changed files with 25 additions and 3 deletions

View File

@ -422,4 +422,6 @@ def pytest_report_unserialize(data):
return TestReport._from_json(data) return TestReport._from_json(data)
elif data["_report_type"] == "CollectReport": elif data["_report_type"] == "CollectReport":
return CollectReport._from_json(data) return CollectReport._from_json(data)
assert "Unknown report_type unserialize data: {}".format(data["_report_type"]) assert False, "Unknown report_type unserialize data: {}".format(
data["_report_type"]
)

View File

@ -249,7 +249,6 @@ class TestHooks:
def test_test_report(self, testdir, pytestconfig): def test_test_report(self, testdir, pytestconfig):
testdir.makepyfile( testdir.makepyfile(
""" """
import os
def test_a(): assert False def test_a(): assert False
def test_b(): pass def test_b(): pass
""" """
@ -272,7 +271,6 @@ class TestHooks:
def test_collect_report(self, testdir, pytestconfig): def test_collect_report(self, testdir, pytestconfig):
testdir.makepyfile( testdir.makepyfile(
""" """
import os
def test_a(): assert False def test_a(): assert False
def test_b(): pass def test_b(): pass
""" """
@ -291,3 +289,25 @@ class TestHooks:
assert new_rep.nodeid == rep.nodeid assert new_rep.nodeid == rep.nodeid
assert new_rep.when == "collect" assert new_rep.when == "collect"
assert new_rep.outcome == rep.outcome assert new_rep.outcome == rep.outcome
@pytest.mark.parametrize(
"hook_name", ["pytest_runtest_logreport", "pytest_collectreport"]
)
def test_invalid_report_types(self, testdir, pytestconfig, hook_name):
testdir.makepyfile(
"""
def test_a(): pass
"""
)
reprec = testdir.inline_run()
reports = reprec.getreports(hook_name)
assert reports
rep = reports[0]
data = pytestconfig.hook.pytest_report_serialize(
config=pytestconfig, report=rep
)
data["_report_type"] = "Unknown"
with pytest.raises(AssertionError):
_ = pytestconfig.hook.pytest_report_unserialize(
config=pytestconfig, data=data
)