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)
| 445 | |
| 446 | |
| 447 | def _report_to_json(report: BaseReport) -> Dict[str, Any]: |
| 448 | """Return the contents of this report as a dict of builtin entries, |
| 449 | suitable for serialization. |
| 450 | |
| 451 | This was originally the serialize_report() function from xdist (ca03269). |
| 452 | """ |
| 453 | |
| 454 | def serialize_repr_entry( |
| 455 | entry: Union[ReprEntry, ReprEntryNative] |
| 456 | ) -> Dict[str, Any]: |
| 457 | data = attr.asdict(entry) |
| 458 | for key, value in data.items(): |
| 459 | if hasattr(value, "__dict__"): |
| 460 | data[key] = attr.asdict(value) |
| 461 | entry_data = {"type": type(entry).__name__, "data": data} |
| 462 | return entry_data |
| 463 | |
| 464 | def serialize_repr_traceback(reprtraceback: ReprTraceback) -> Dict[str, Any]: |
| 465 | result = attr.asdict(reprtraceback) |
| 466 | result["reprentries"] = [ |
| 467 | serialize_repr_entry(x) for x in reprtraceback.reprentries |
| 468 | ] |
| 469 | return result |
| 470 | |
| 471 | def serialize_repr_crash( |
| 472 | reprcrash: Optional[ReprFileLocation], |
| 473 | ) -> Optional[Dict[str, Any]]: |
| 474 | if reprcrash is not None: |
| 475 | return attr.asdict(reprcrash) |
| 476 | else: |
| 477 | return None |
| 478 | |
| 479 | def serialize_exception_longrepr(rep: BaseReport) -> Dict[str, Any]: |
| 480 | assert rep.longrepr is not None |
| 481 | # TODO: Investigate whether the duck typing is really necessary here. |
| 482 | longrepr = cast(ExceptionRepr, rep.longrepr) |
| 483 | result: Dict[str, Any] = { |
| 484 | "reprcrash": serialize_repr_crash(longrepr.reprcrash), |
| 485 | "reprtraceback": serialize_repr_traceback(longrepr.reprtraceback), |
| 486 | "sections": longrepr.sections, |
| 487 | } |
| 488 | if isinstance(longrepr, ExceptionChainRepr): |
| 489 | result["chain"] = [] |
| 490 | for repr_traceback, repr_crash, description in longrepr.chain: |
| 491 | result["chain"].append( |
| 492 | ( |
| 493 | serialize_repr_traceback(repr_traceback), |
| 494 | serialize_repr_crash(repr_crash), |
| 495 | description, |
| 496 | ) |
| 497 | ) |
| 498 | else: |
| 499 | result["chain"] = None |
| 500 | return result |
| 501 | |
| 502 | d = report.__dict__.copy() |
| 503 | if hasattr(report.longrepr, "toterminal"): |
| 504 | if hasattr(report.longrepr, "reprtraceback") and hasattr( |
no test coverage detected