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

Function _report_to_json

src/_pytest/reports.py:541–611  ·  view source on GitHub ↗

Return the contents of this report as a dict of builtin entries, suitable for serialization. This was originally the serialize_report() function from xdist (ca03269).

(report: BaseReport)

Source from the content-addressed store, hash-verified

539
540
541def _report_to_json(report: BaseReport) -> dict[str, Any]:
542 """Return the contents of this report as a dict of builtin entries,
543 suitable for serialization.
544
545 This was originally the serialize_report() function from xdist (ca03269).
546 """
547
548 def serialize_repr_entry(
549 entry: ReprEntry | ReprEntryNative,
550 ) -> dict[str, Any]:
551 data = dataclasses.asdict(entry)
552 for key, value in data.items():
553 if hasattr(value, "__dict__"):
554 data[key] = dataclasses.asdict(value)
555 entry_data = {"type": type(entry).__name__, "data": data}
556 return entry_data
557
558 def serialize_repr_traceback(reprtraceback: ReprTraceback) -> dict[str, Any]:
559 result = dataclasses.asdict(reprtraceback)
560 result["reprentries"] = [
561 serialize_repr_entry(x) for x in reprtraceback.reprentries
562 ]
563 return result
564
565 def serialize_repr_crash(
566 reprcrash: ReprFileLocation | None,
567 ) -> dict[str, Any] | None:
568 if reprcrash is not None:
569 return dataclasses.asdict(reprcrash)
570 else:
571 return None
572
573 def serialize_exception_longrepr(rep: BaseReport) -> dict[str, Any]:
574 assert rep.longrepr is not None
575 # TODO: Investigate whether the duck typing is really necessary here.
576 longrepr = cast(ExceptionRepr, rep.longrepr)
577 result: dict[str, Any] = {
578 "reprcrash": serialize_repr_crash(longrepr.reprcrash),
579 "reprtraceback": serialize_repr_traceback(longrepr.reprtraceback),
580 "sections": longrepr.sections,
581 }
582 if isinstance(longrepr, ExceptionChainRepr):
583 result["chain"] = []
584 for repr_traceback, repr_crash, description in longrepr.chain:
585 result["chain"].append(
586 (
587 serialize_repr_traceback(repr_traceback),
588 serialize_repr_crash(repr_crash),
589 description,
590 )
591 )
592 else:
593 result["chain"] = None
594 return result
595
596 d = report.__dict__.copy()
597 if hasattr(report.longrepr, "toterminal"):
598 if hasattr(report.longrepr, "reprtraceback") and hasattr(

Callers 1

_to_jsonMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…