| 78 | |
| 79 | @dataclasses.dataclass(init=False) |
| 80 | class SubtestReport(TestReport): |
| 81 | context: SubtestContext |
| 82 | |
| 83 | @property |
| 84 | def head_line(self) -> str: |
| 85 | _, _, domain = self.location |
| 86 | return f"{domain} {self._sub_test_description()}" |
| 87 | |
| 88 | def _sub_test_description(self) -> str: |
| 89 | parts = [] |
| 90 | if self.context.msg is not None: |
| 91 | parts.append(f"[{self.context.msg}]") |
| 92 | if self.context.kwargs: |
| 93 | params_desc = ", ".join( |
| 94 | f"{k}={v}" for (k, v) in self.context.kwargs.items() |
| 95 | ) |
| 96 | parts.append(f"({params_desc})") |
| 97 | return " ".join(parts) or "(<subtest>)" |
| 98 | |
| 99 | def _to_json(self) -> dict[str, Any]: |
| 100 | data = super()._to_json() |
| 101 | del data["context"] |
| 102 | data["_report_type"] = "SubTestReport" |
| 103 | data["_subtest.context"] = self.context._to_json() |
| 104 | return data |
| 105 | |
| 106 | @classmethod |
| 107 | def _from_json(cls, reportdict: dict[str, Any]) -> SubtestReport: |
| 108 | report = super()._from_json(reportdict) |
| 109 | report.context = SubtestContext._from_json(reportdict["_subtest.context"]) |
| 110 | return report |
| 111 | |
| 112 | @classmethod |
| 113 | def _new( |
| 114 | cls, |
| 115 | test_report: TestReport, |
| 116 | context: SubtestContext, |
| 117 | captured_output: Captured | None, |
| 118 | captured_logs: CapturedLogs | None, |
| 119 | ) -> Self: |
| 120 | result = super()._from_json(test_report._to_json()) |
| 121 | result.context = context |
| 122 | |
| 123 | if captured_output: |
| 124 | if captured_output.out: |
| 125 | result.sections.append(("Captured stdout call", captured_output.out)) |
| 126 | if captured_output.err: |
| 127 | result.sections.append(("Captured stderr call", captured_output.err)) |
| 128 | |
| 129 | if captured_logs and (log := captured_logs.handler.stream.getvalue()): |
| 130 | result.sections.append(("Captured log call", log)) |
| 131 | |
| 132 | return result |
| 133 | |
| 134 | |
| 135 | @fixture |
no outgoing calls