Rename hooks: to/from_serializable
This commit is contained in:
parent
9311d822c7
commit
65c8e8a09e
|
@ -1,4 +1,4 @@
|
||||||
New ``pytest_report_serialize`` and ``pytest_report_unserialize`` **experimental** hooks.
|
New ``pytest_report_to_serializable`` and ``pytest_report_from_serializable`` **experimental** hooks.
|
||||||
|
|
||||||
These hooks will be used by ``pytest-xdist``, ``pytest-subtests``, and the replacement for
|
These hooks will be used by ``pytest-xdist``, ``pytest-subtests``, and the replacement for
|
||||||
resultlog to serialize and customize reports.
|
resultlog to serialize and customize reports.
|
||||||
|
|
|
@ -376,7 +376,7 @@ def pytest_runtest_logreport(report):
|
||||||
|
|
||||||
|
|
||||||
@hookspec(firstresult=True)
|
@hookspec(firstresult=True)
|
||||||
def pytest_report_serialize(config, report):
|
def pytest_report_to_serializable(config, report):
|
||||||
"""
|
"""
|
||||||
.. warning::
|
.. warning::
|
||||||
This hook is experimental and subject to change between pytest releases, even
|
This hook is experimental and subject to change between pytest releases, even
|
||||||
|
@ -394,7 +394,7 @@ def pytest_report_serialize(config, report):
|
||||||
|
|
||||||
|
|
||||||
@hookspec(firstresult=True)
|
@hookspec(firstresult=True)
|
||||||
def pytest_report_unserialize(config, data):
|
def pytest_report_from_serializable(config, data):
|
||||||
"""
|
"""
|
||||||
.. warning::
|
.. warning::
|
||||||
This hook is experimental and subject to change between pytest releases, even
|
This hook is experimental and subject to change between pytest releases, even
|
||||||
|
@ -406,7 +406,7 @@ def pytest_report_unserialize(config, data):
|
||||||
|
|
||||||
In the future it might become part of the public hook API.
|
In the future it might become part of the public hook API.
|
||||||
|
|
||||||
Restores a report object previously serialized with pytest_report_serialize().
|
Restores a report object previously serialized with pytest_report_to_serializable().
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -409,14 +409,14 @@ class CollectErrorRepr(TerminalRepr):
|
||||||
out.line(self.longrepr, red=True)
|
out.line(self.longrepr, red=True)
|
||||||
|
|
||||||
|
|
||||||
def pytest_report_serialize(report):
|
def pytest_report_to_serializable(report):
|
||||||
if isinstance(report, (TestReport, CollectReport)):
|
if isinstance(report, (TestReport, CollectReport)):
|
||||||
data = report._to_json()
|
data = report._to_json()
|
||||||
data["_report_type"] = report.__class__.__name__
|
data["_report_type"] = report.__class__.__name__
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def pytest_report_unserialize(data):
|
def pytest_report_from_serializable(data):
|
||||||
if "_report_type" in data:
|
if "_report_type" in data:
|
||||||
if data["_report_type"] == "TestReport":
|
if data["_report_type"] == "TestReport":
|
||||||
return TestReport._from_json(data)
|
return TestReport._from_json(data)
|
||||||
|
|
|
@ -257,11 +257,11 @@ class TestHooks:
|
||||||
reports = reprec.getreports("pytest_runtest_logreport")
|
reports = reprec.getreports("pytest_runtest_logreport")
|
||||||
assert len(reports) == 6
|
assert len(reports) == 6
|
||||||
for rep in reports:
|
for rep in reports:
|
||||||
data = pytestconfig.hook.pytest_report_serialize(
|
data = pytestconfig.hook.pytest_report_to_serializable(
|
||||||
config=pytestconfig, report=rep
|
config=pytestconfig, report=rep
|
||||||
)
|
)
|
||||||
assert data["_report_type"] == "TestReport"
|
assert data["_report_type"] == "TestReport"
|
||||||
new_rep = pytestconfig.hook.pytest_report_unserialize(
|
new_rep = pytestconfig.hook.pytest_report_from_serializable(
|
||||||
config=pytestconfig, data=data
|
config=pytestconfig, data=data
|
||||||
)
|
)
|
||||||
assert new_rep.nodeid == rep.nodeid
|
assert new_rep.nodeid == rep.nodeid
|
||||||
|
@ -279,11 +279,11 @@ class TestHooks:
|
||||||
reports = reprec.getreports("pytest_collectreport")
|
reports = reprec.getreports("pytest_collectreport")
|
||||||
assert len(reports) == 2
|
assert len(reports) == 2
|
||||||
for rep in reports:
|
for rep in reports:
|
||||||
data = pytestconfig.hook.pytest_report_serialize(
|
data = pytestconfig.hook.pytest_report_to_serializable(
|
||||||
config=pytestconfig, report=rep
|
config=pytestconfig, report=rep
|
||||||
)
|
)
|
||||||
assert data["_report_type"] == "CollectReport"
|
assert data["_report_type"] == "CollectReport"
|
||||||
new_rep = pytestconfig.hook.pytest_report_unserialize(
|
new_rep = pytestconfig.hook.pytest_report_from_serializable(
|
||||||
config=pytestconfig, data=data
|
config=pytestconfig, data=data
|
||||||
)
|
)
|
||||||
assert new_rep.nodeid == rep.nodeid
|
assert new_rep.nodeid == rep.nodeid
|
||||||
|
@ -303,11 +303,11 @@ class TestHooks:
|
||||||
reports = reprec.getreports(hook_name)
|
reports = reprec.getreports(hook_name)
|
||||||
assert reports
|
assert reports
|
||||||
rep = reports[0]
|
rep = reports[0]
|
||||||
data = pytestconfig.hook.pytest_report_serialize(
|
data = pytestconfig.hook.pytest_report_to_serializable(
|
||||||
config=pytestconfig, report=rep
|
config=pytestconfig, report=rep
|
||||||
)
|
)
|
||||||
data["_report_type"] = "Unknown"
|
data["_report_type"] = "Unknown"
|
||||||
with pytest.raises(AssertionError):
|
with pytest.raises(AssertionError):
|
||||||
_ = pytestconfig.hook.pytest_report_unserialize(
|
_ = pytestconfig.hook.pytest_report_from_serializable(
|
||||||
config=pytestconfig, data=data
|
config=pytestconfig, data=data
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue