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

Class SubtestContext

src/_pytest/subtests.py:58–76  ·  view source on GitHub ↗

The values passed to Subtests.test() that are included in the test report.

Source from the content-addressed store, hash-verified

56
57@dataclasses.dataclass(frozen=True, slots=True, kw_only=True)
58class SubtestContext:
59 """The values passed to Subtests.test() that are included in the test report."""
60
61 msg: str | None
62 kwargs: Mapping[str, Any]
63
64 def __post_init__(self) -> None:
65 # Brute-force the returned kwargs dict to be JSON serializable (pytest-dev/pytest-xdist#1273).
66 object.__setattr__(
67 self, "kwargs", {k: saferepr(v) for (k, v) in self.kwargs.items()}
68 )
69
70 def _to_json(self) -> dict[str, Any]:
71 result = dataclasses.asdict(self)
72 return result
73
74 @classmethod
75 def _from_json(cls, d: dict[str, Any]) -> Self:
76 return cls(msg=d["msg"], kwargs=d["kwargs"])
77
78
79@dataclasses.dataclass(init=False)

Callers 3

addSubTestMethod · 0.90
test_serializationFunction · 0.90
__exit__Method · 0.85

Calls

no outgoing calls

Tested by 3

addSubTestMethod · 0.72
test_serializationFunction · 0.72
__exit__Method · 0.68