From fb6b7ac181fc8ecf2da34e9a18f077dea15983a7 Mon Sep 17 00:00:00 2001 From: Brian Okken <1568356+okken@users.noreply.github.com> Date: Wed, 3 Jan 2024 22:27:19 -0800 Subject: [PATCH] Change refactor so it doesn't break pytest-sugar --- AUTHORS | 1 + .../{11574.feature.rst => 11233.feature.rst} | 2 +- src/_pytest/terminal.py | 34 ++++++++++++------- 3 files changed, 24 insertions(+), 13 deletions(-) rename changelog/{11574.feature.rst => 11233.feature.rst} (84%) diff --git a/AUTHORS b/AUTHORS index 42cfd0be2..537e40df0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -137,6 +137,7 @@ Erik Hasse Erik M. Bray Evan Kepner Evgeny Seliverstov +Fabian Sturm Fabien Zarifian Fabio Zadrozny Felix Hofstätter diff --git a/changelog/11574.feature.rst b/changelog/11233.feature.rst similarity index 84% rename from changelog/11574.feature.rst rename to changelog/11233.feature.rst index c59480e45..75f3742ff 100644 --- a/changelog/11574.feature.rst +++ b/changelog/11233.feature.rst @@ -1 +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. \ No newline at end of file +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. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index ae2b3b56a..b91a97221 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -877,11 +877,11 @@ class TerminalReporter: @hookimpl(wrapper=True) def pytest_terminal_summary(self) -> Generator[None, None, None]: self.summary_errors() - self.summary_failures("failed", "FAILURES") - self.summary_failures("xfailed", "XFAILURES", "x") + self.summary_failures() + self.summary_xfailures() self.summary_warnings() - self.summary_passes("passed", "PASSES", "P") - self.summary_passes("xpassed", "XPASSES", "X") + self.summary_passes() + self.summary_xpasses() try: return (yield) finally: @@ -1010,10 +1010,15 @@ class TerminalReporter: "-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html" ) - def summary_passes(self, - which_reports: str, - sep_title: str, - needed_opt: str) -> None: + def summary_passes(self) -> None: + self.summary_passes_combined("passed", "PASSES", "P") + + def summary_xpasses(self) -> None: + self.summary_passes_combined("xpassed", "XPASSES", "X") + + def summary_passes_combined( + self, which_reports: str, sep_title: str, needed_opt: str + ) -> None: if self.config.option.tbstyle != "no": if self.hasopt(needed_opt): reports: List[TestReport] = self.getreports(which_reports) @@ -1052,10 +1057,15 @@ class TerminalReporter: content = content[:-1] self._tw.line(content) - def summary_failures(self, - which_reports: str, - sep_title: str, - needed_opt: Optional[str] = None) -> None: + def summary_failures(self) -> None: + self.summary_failures_combined("failed", "FAILURES") + + def summary_xfailures(self) -> None: + self.summary_failures_combined("xfailed", "XFAILURES", "x") + + def summary_failures_combined( + self, which_reports: str, sep_title: str, needed_opt: Optional[str] = None + ) -> None: if self.config.option.tbstyle != "no": if not needed_opt or self.hasopt(needed_opt): reports: List[BaseReport] = self.getreports(which_reports)