Refactor `summary_failures()` and `summary_passes()` to handle the `x` variants.

Add feature changelog entry.
This commit is contained in:
Brian Okken 2024-01-03 15:56:17 -08:00
parent 958ba23d96
commit f35c5ef0cf
2 changed files with 19 additions and 43 deletions

View File

@ -0,0 +1 @@
Report tracebacks for xfailures when ``-rx`` is set. Report captured output for xpasses when ``-rX`` is set. For xpasses, add ``-`` in summary between test name and reason, to match the format of xfail. Addresses issue #11233.

View File

@ -877,11 +877,11 @@ class TerminalReporter:
@hookimpl(wrapper=True) @hookimpl(wrapper=True)
def pytest_terminal_summary(self) -> Generator[None, None, None]: def pytest_terminal_summary(self) -> Generator[None, None, None]:
self.summary_errors() self.summary_errors()
self.summary_failures() self.summary_failures("failed", "FAILURES")
self.summary_xfailures() self.summary_failures("xfailed", "XFAILURES", "x")
self.summary_warnings() self.summary_warnings()
self.summary_passes() self.summary_passes("passed", "PASSES", "P")
self.summary_xpasses() self.summary_passes("xpassed", "XPASSES", "X")
try: try:
return (yield) return (yield)
finally: finally:
@ -1010,27 +1010,16 @@ class TerminalReporter:
"-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html" "-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html"
) )
def summary_passes(self) -> None: def summary_passes(self,
which_reports: str,
sep_title: str,
needed_opt: str) -> None:
if self.config.option.tbstyle != "no": if self.config.option.tbstyle != "no":
if self.hasopt("P"): if self.hasopt(needed_opt):
reports: List[TestReport] = self.getreports("passed") reports: List[TestReport] = self.getreports(which_reports)
if not reports: if not reports:
return return
self.write_sep("=", "PASSES") self.write_sep("=", sep_title)
for rep in reports:
if rep.sections:
msg = self._getfailureheadline(rep)
self.write_sep("_", msg, green=True, bold=True)
self._outrep_summary(rep)
self._handle_teardown_sections(rep.nodeid)
def summary_xpasses(self) -> None:
if self.config.option.tbstyle != "no":
if self.hasopt("X"):
reports: List[TestReport] = self.getreports("xpassed")
if not reports:
return
self.write_sep("=", "XPASSES")
for rep in reports: for rep in reports:
if rep.sections: if rep.sections:
msg = self._getfailureheadline(rep) msg = self._getfailureheadline(rep)
@ -1063,30 +1052,16 @@ class TerminalReporter:
content = content[:-1] content = content[:-1]
self._tw.line(content) self._tw.line(content)
def summary_failures(self) -> None: def summary_failures(self,
which_reports: str,
sep_title: str,
needed_opt:str|None = None) -> None:
if self.config.option.tbstyle != "no": if self.config.option.tbstyle != "no":
reports: List[BaseReport] = self.getreports("failed") if not needed_opt or self.hasopt(needed_opt):
reports: List[BaseReport] = self.getreports(which_reports)
if not reports: if not reports:
return return
self.write_sep("=", "FAILURES") self.write_sep("=", sep_title)
if self.config.option.tbstyle == "line":
for rep in reports:
line = self._getcrashline(rep)
self.write_line(line)
else:
for rep in reports:
msg = self._getfailureheadline(rep)
self.write_sep("_", msg, red=True, bold=True)
self._outrep_summary(rep)
self._handle_teardown_sections(rep.nodeid)
def summary_xfailures(self) -> None:
if self.config.option.tbstyle != "no":
if self.hasopt("x"):
reports: List[BaseReport] = self.getreports("xfailed")
if not reports:
return
self.write_sep("=", "XFAILURES")
if self.config.option.tbstyle == "line": if self.config.option.tbstyle == "line":
for rep in reports: for rep in reports:
line = self._getcrashline(rep) line = self._getcrashline(rep)