Skip to content

Commit 1abbe00

Browse files
committed
feat: add --fold-skipped=yes|no cli option
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: #9876 Signed-off-by: Pavel Březina <[email protected]>
1 parent ac41898 commit 1abbe00

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

changelog/12567.feature.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Added ``--no-fold-skipped`` command line option
2+
3+
If this option is set, then skipped tests in short summary are no longer grouped
4+
by reason but all tests are printed individually with correct nodeid in the same
5+
way as other statuses.
6+
7+
-- by :user:`pbrezina`

src/_pytest/terminal.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ def pytest_addoption(parser: Parser) -> None:
154154
dest="no_summary",
155155
help="Disable summary",
156156
)
157+
group._addoption(
158+
"--no-fold-skipped",
159+
action="store_false",
160+
dest="fold_skipped",
161+
default=True,
162+
help="Do not fold skipped tests in short summary.",
163+
)
157164
group._addoption(
158165
"-q",
159166
"--quiet",
@@ -371,6 +378,7 @@ def __init__(self, config: Config, file: TextIO | None = None) -> None:
371378
self._screen_width = self._tw.fullwidth
372379
self.currentfspath: None | Path | str | int = None
373380
self.reportchars = getreportopt(config)
381+
self.foldskipped = config.option.fold_skipped
374382
self.hasmarkup = self._tw.hasmarkup
375383
self.isatty = file.isatty()
376384
self._progress_nodeids_reported: set[str] = set()
@@ -1232,7 +1240,7 @@ def show_xpassed(lines: list[str]) -> None:
12321240
line += " - " + str(reason)
12331241
lines.append(line)
12341242

1235-
def show_skipped(lines: list[str]) -> None:
1243+
def show_skipped_folded(lines: list[str]) -> None:
12361244
skipped: list[CollectReport] = self.stats.get("skipped", [])
12371245
fskips = _folded_skips(self.startpath, skipped) if skipped else []
12381246
if not fskips:
@@ -1252,6 +1260,31 @@ def show_skipped(lines: list[str]) -> None:
12521260
else:
12531261
lines.append("%s [%d] %s: %s" % (markup_word, num, fspath, reason))
12541262

1263+
def show_skipped_unfolded(lines: list[str]) -> None:
1264+
skipped: list[CollectReport] = self.stats.get("skipped", [])
1265+
1266+
for rep in skipped:
1267+
assert rep.longrepr is not None
1268+
assert isinstance(rep.longrepr, tuple), (rep, rep.longrepr)
1269+
assert len(rep.longrepr) == 3, (rep, rep.longrepr)
1270+
1271+
verbose_word, verbose_markup = rep._get_verbose_word_with_markup(
1272+
self.config, {_color_for_type["warnings"]: True}
1273+
)
1274+
markup_word = self._tw.markup(verbose_word, **verbose_markup)
1275+
nodeid = _get_node_id_with_markup(self._tw, self.config, rep)
1276+
line = f"{markup_word} {nodeid}"
1277+
reason = rep.longrepr[2]
1278+
if reason:
1279+
line += " - " + str(reason)
1280+
lines.append(line)
1281+
1282+
def show_skipped(lines: list[str]) -> None:
1283+
if self.foldskipped:
1284+
show_skipped_folded(lines)
1285+
else:
1286+
show_skipped_unfolded(lines)
1287+
12551288
REPORTCHAR_ACTIONS: Mapping[str, Callable[[list[str]], None]] = {
12561289
"x": show_xfailed,
12571290
"X": show_xpassed,

testing/test_terminal.py

+38
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,44 @@ def test():
11501150
result.stdout.fnmatch_lines([expected])
11511151
assert result.stdout.lines.count(expected) == 1
11521152

1153+
def test_summary_s_folded(self, pytester: Pytester) -> None:
1154+
"""Test that skipped tests are correctly folded"""
1155+
pytester.makepyfile(
1156+
"""
1157+
import pytest
1158+
1159+
@pytest.mark.parametrize("param", [True, False])
1160+
@pytest.mark.skip("Some reason")
1161+
def test(param):
1162+
pass
1163+
"""
1164+
)
1165+
result = pytester.runpytest("-rs")
1166+
expected = "SKIPPED [2] test_summary_s_folded.py:3: Some reason"
1167+
result.stdout.fnmatch_lines([expected])
1168+
assert result.stdout.lines.count(expected) == 1
1169+
1170+
def test_summary_s_unfolded(self, pytester: Pytester) -> None:
1171+
"""Test that skipped tests are not folded if --no-fold-skipped is set"""
1172+
pytester.makepyfile(
1173+
"""
1174+
import pytest
1175+
1176+
@pytest.mark.parametrize("param", [True, False])
1177+
@pytest.mark.skip("Some reason")
1178+
def test(param):
1179+
pass
1180+
"""
1181+
)
1182+
result = pytester.runpytest("-rs", "--no-fold-skipped")
1183+
expected = [
1184+
"SKIPPED test_summary_s_unfolded.py::test[True] - Skipped: Some reason",
1185+
"SKIPPED test_summary_s_unfolded.py::test[False] - Skipped: Some reason",
1186+
]
1187+
result.stdout.fnmatch_lines(expected)
1188+
assert result.stdout.lines.count(expected[0]) == 1
1189+
assert result.stdout.lines.count(expected[1]) == 1
1190+
11531191

11541192
@pytest.mark.parametrize(
11551193
("use_ci", "expected_message"),

0 commit comments

Comments
 (0)