Skip to content

Commit 65c8e8a

Browse files
committed
Rename hooks: to/from_serializable
1 parent 9311d82 commit 65c8e8a

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

changelog/4965.trivial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
New ``pytest_report_serialize`` and ``pytest_report_unserialize`` **experimental** hooks.
1+
New ``pytest_report_to_serializable`` and ``pytest_report_from_serializable`` **experimental** hooks.
22

33
These hooks will be used by ``pytest-xdist``, ``pytest-subtests``, and the replacement for
44
resultlog to serialize and customize reports.

src/_pytest/hookspec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def pytest_runtest_logreport(report):
376376

377377

378378
@hookspec(firstresult=True)
379-
def pytest_report_serialize(config, report):
379+
def pytest_report_to_serializable(config, report):
380380
"""
381381
.. warning::
382382
This hook is experimental and subject to change between pytest releases, even
@@ -394,7 +394,7 @@ def pytest_report_serialize(config, report):
394394

395395

396396
@hookspec(firstresult=True)
397-
def pytest_report_unserialize(config, data):
397+
def pytest_report_from_serializable(config, data):
398398
"""
399399
.. warning::
400400
This hook is experimental and subject to change between pytest releases, even
@@ -406,7 +406,7 @@ def pytest_report_unserialize(config, data):
406406
407407
In the future it might become part of the public hook API.
408408
409-
Restores a report object previously serialized with pytest_report_serialize().
409+
Restores a report object previously serialized with pytest_report_to_serializable().
410410
"""
411411

412412

src/_pytest/reports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,14 @@ def toterminal(self, out):
409409
out.line(self.longrepr, red=True)
410410

411411

412-
def pytest_report_serialize(report):
412+
def pytest_report_to_serializable(report):
413413
if isinstance(report, (TestReport, CollectReport)):
414414
data = report._to_json()
415415
data["_report_type"] = report.__class__.__name__
416416
return data
417417

418418

419-
def pytest_report_unserialize(data):
419+
def pytest_report_from_serializable(data):
420420
if "_report_type" in data:
421421
if data["_report_type"] == "TestReport":
422422
return TestReport._from_json(data)

testing/test_reports.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ def test_b(): pass
257257
reports = reprec.getreports("pytest_runtest_logreport")
258258
assert len(reports) == 6
259259
for rep in reports:
260-
data = pytestconfig.hook.pytest_report_serialize(
260+
data = pytestconfig.hook.pytest_report_to_serializable(
261261
config=pytestconfig, report=rep
262262
)
263263
assert data["_report_type"] == "TestReport"
264-
new_rep = pytestconfig.hook.pytest_report_unserialize(
264+
new_rep = pytestconfig.hook.pytest_report_from_serializable(
265265
config=pytestconfig, data=data
266266
)
267267
assert new_rep.nodeid == rep.nodeid
@@ -279,11 +279,11 @@ def test_b(): pass
279279
reports = reprec.getreports("pytest_collectreport")
280280
assert len(reports) == 2
281281
for rep in reports:
282-
data = pytestconfig.hook.pytest_report_serialize(
282+
data = pytestconfig.hook.pytest_report_to_serializable(
283283
config=pytestconfig, report=rep
284284
)
285285
assert data["_report_type"] == "CollectReport"
286-
new_rep = pytestconfig.hook.pytest_report_unserialize(
286+
new_rep = pytestconfig.hook.pytest_report_from_serializable(
287287
config=pytestconfig, data=data
288288
)
289289
assert new_rep.nodeid == rep.nodeid
@@ -303,11 +303,11 @@ def test_a(): pass
303303
reports = reprec.getreports(hook_name)
304304
assert reports
305305
rep = reports[0]
306-
data = pytestconfig.hook.pytest_report_serialize(
306+
data = pytestconfig.hook.pytest_report_to_serializable(
307307
config=pytestconfig, report=rep
308308
)
309309
data["_report_type"] = "Unknown"
310310
with pytest.raises(AssertionError):
311-
_ = pytestconfig.hook.pytest_report_unserialize(
311+
_ = pytestconfig.hook.pytest_report_from_serializable(
312312
config=pytestconfig, data=data
313313
)

0 commit comments

Comments
 (0)