MCPcopy
hub / github.com/pytest-dev/pytest / test_serialization

Function test_serialization

testing/test_subtests.py:1026–1048  ·  testing/test_subtests.py::test_serialization

Ensure subtest's kwargs are serialized using `saferepr` (pytest-dev/pytest-xdist#1273).

()

Source from the content-addressed store, hash-verified

1024
1025
1026def test_serialization() -> None:
1027 class="st">""class="st">"Ensure subtest&class="cm">#x27;s kwargs are serialized using `saferepr` (pytest-dev/pytest-xdist#1273)."class="st">""
1028 from _pytest.subtests import pytest_report_from_serializable
1029 from _pytest.subtests import pytest_report_to_serializable
1030
1031 report = SubtestReport(
1032 class="st">"test_foo::test_foo",
1033 (class="st">"test_foo.py", 12, class="st">""),
1034 keywords={},
1035 outcome=class="st">"passed",
1036 when=class="st">"call",
1037 longrepr=None,
1038 context=SubtestContext(msg=class="st">"custom message", kwargs=dict(i=10, a=MyEnum.A)),
1039 )
1040 data = pytest_report_to_serializable(report)
1041 assert data is not None
1042 class="cm"># Ensure the report is actually serializable to JSON.
1043 _ = json.dumps(data)
1044 new_report = pytest_report_from_serializable(data)
1045 assert new_report is not None
1046 assert new_report.context == SubtestContext(
1047 msg=class="st">"custom message", kwargs=dict(i=saferepr(10), a=saferepr(MyEnum.A))
1048 )
1049
1050
1051def test_serialization_xdist(pytester: pytest.Pytester) -> None: class="cm"># pragma: no cover

Callers

nothing calls this directly

Calls 6

SubtestReportClass · 0.90
SubtestContextClass · 0.90
safereprFunction · 0.90
dumpsMethod · 0.80

Tested by

no test coverage detected