From 59c925caae5beef33c006f706a18bc95944070de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= Date: Wed, 3 Jul 2024 14:54:33 +0200 Subject: [PATCH 1/2] feat: add --fold-skipped=yes|no cli option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This controlls how the skipped tests are display in the short summary. - yes (default): keeps the current behavior that folds the skipped tests together - no: each skipped test is on its own line, display as any other status Resolves: https://github.com/pytest-dev/pytest/issues/9876 Signed-off-by: Pavel Březina --- src/_pytest/terminal.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index f364316e2..4e5e8623c 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -154,6 +154,15 @@ def pytest_addoption(parser: Parser) -> None: dest="no_summary", help="Disable summary", ) + group._addoption( + "--fold-skipped", + action="store", + dest="foldskipped", + choices=["no", "yes"], + default="yes", + help="Whether to fold skipped tests in short summary or not. " + "Default: yes.", + ) group._addoption( "-q", "--quiet", @@ -371,6 +380,7 @@ class TerminalReporter: self._screen_width = self._tw.fullwidth self.currentfspath: None | Path | str | int = None self.reportchars = getreportopt(config) + self.foldskipped = True if config.option.foldskipped == "yes" else False self.hasmarkup = self._tw.hasmarkup self.isatty = file.isatty() self._progress_nodeids_reported: set[str] = set() @@ -1232,7 +1242,7 @@ class TerminalReporter: line += " - " + str(reason) lines.append(line) - def show_skipped(lines: list[str]) -> None: + def show_skipped_folded(lines: list[str]) -> None: skipped: list[CollectReport] = self.stats.get("skipped", []) fskips = _folded_skips(self.startpath, skipped) if skipped else [] if not fskips: @@ -1252,6 +1262,31 @@ class TerminalReporter: else: lines.append("%s [%d] %s: %s" % (markup_word, num, fspath, reason)) + def show_skipped_unfolded(lines: list[str]) -> None: + skipped: list[CollectReport] = self.stats.get("skipped", []) + + for rep in skipped: + assert rep.longrepr is not None + assert isinstance(rep.longrepr, tuple), (rep, rep.longrepr) + assert len(rep.longrepr) == 3, (rep, rep.longrepr) + + verbose_word, verbose_markup = rep._get_verbose_word_with_markup( + self.config, {_color_for_type["warnings"]: True} + ) + markup_word = self._tw.markup(verbose_word, **verbose_markup) + nodeid = _get_node_id_with_markup(self._tw, self.config, rep) + line = f"{markup_word} {nodeid}" + reason = rep.longrepr[2] + if reason: + line += " - " + str(reason) + lines.append(line) + + def show_skipped(lines: list[str]) -> None: + if self.foldskipped: + show_skipped_folded(lines) + else: + show_skipped_unfolded(lines) + REPORTCHAR_ACTIONS: Mapping[str, Callable[[list[str]], None]] = { "x": show_xfailed, "X": show_xpassed, From c980d64c6793c0780f8ad327a4d4ecf30e77713f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:59:45 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/terminal.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 4e5e8623c..2904995c6 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -160,8 +160,7 @@ def pytest_addoption(parser: Parser) -> None: dest="foldskipped", choices=["no", "yes"], default="yes", - help="Whether to fold skipped tests in short summary or not. " - "Default: yes.", + help="Whether to fold skipped tests in short summary or not. " "Default: yes.", ) group._addoption( "-q",