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

Method summary_warnings

src/_pytest/terminal.py:1088–1140  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1086 return [x for x in self.stats.get(name, ()) if not hasattr(x, "_pdbshown")]
1087
1088 def summary_warnings(self) -> None:
1089 if self.hasopt("w"):
1090 all_warnings: list[WarningReport] | None = self.stats.get("warnings")
1091 if not all_warnings:
1092 return
1093
1094 final = self._already_displayed_warnings is not None
1095 if final:
1096 warning_reports = all_warnings[self._already_displayed_warnings :]
1097 else:
1098 warning_reports = all_warnings
1099 self._already_displayed_warnings = len(warning_reports)
1100 if not warning_reports:
1101 return
1102
1103 reports_grouped_by_message: dict[str, list[WarningReport]] = {}
1104 for wr in warning_reports:
1105 reports_grouped_by_message.setdefault(wr.message, []).append(wr)
1106
1107 def collapsed_location_report(reports: list[WarningReport]) -> str:
1108 locations = []
1109 for w in reports:
1110 location = w.get_location(self.config)
1111 if location:
1112 locations.append(location)
1113
1114 if len(locations) < 10:
1115 return "\n".join(map(str, locations))
1116
1117 counts_by_filename = Counter(
1118 str(loc).split("::", 1)[0] for loc in locations
1119 )
1120 return "\n".join(
1121 "{}: {} warning{}".format(k, v, "s" if v > 1 else "")
1122 for k, v in counts_by_filename.items()
1123 )
1124
1125 title = "warnings summary (final)" if final else "warnings summary"
1126 self.write_sep("=", title, yellow=True, bold=False)
1127 for message, message_reports in reports_grouped_by_message.items():
1128 maybe_location = collapsed_location_report(message_reports)
1129 if maybe_location:
1130 self._tw.line(maybe_location)
1131 lines = message.splitlines()
1132 indented = "\n".join(" " + x for x in lines)
1133 message = indented.rstrip()
1134 else:
1135 message = message.rstrip()
1136 self._tw.line(message)
1137 self._tw.line()
1138 self._tw.line(
1139 "-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html"
1140 )
1141
1142 def summary_passes(self) -> None:
1143 self.summary_passes_combined("passed", "PASSES", "P")

Callers 1

Calls 7

hasoptMethod · 0.95
write_sepMethod · 0.95
appendMethod · 0.80
setdefaultMethod · 0.80
joinMethod · 0.80
getMethod · 0.45
lineMethod · 0.45

Tested by

no test coverage detected