Skip to content

Commit 071250c

Browse files
committed
Show node id for singleton skipped summaries
1 parent addf883 commit 071250c

8 files changed

Lines changed: 48 additions & 31 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ George Kussumoto
189189
Georgy Dyuldin
190190
Gergely Kalmár
191191
Gleb Nikonorov
192+
Goutam Adwant
192193
Graeme Smecher
193194
Graham Horler
194195
Greg Price

changelog/14607.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Single skipped tests in the short test summary now include the test node id instead of only the file and line number.

src/_pytest/terminal.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,10 +1341,15 @@ def show_skipped_folded(lines: list[str]) -> None:
13411341
)
13421342
markup_word = self._tw.markup(verbose_word, **verbose_markup)
13431343
prefix = "Skipped: "
1344-
for num, fspath, lineno, reason in fskips:
1344+
for num, fspath, lineno, reason, single_report in fskips:
13451345
if reason.startswith(prefix):
13461346
reason = reason[len(prefix) :]
1347-
if lineno is not None:
1347+
if single_report is not None:
1348+
nodeid = _get_node_id_with_markup(
1349+
self._tw, self.config, single_report
1350+
)
1351+
lines.append(f"{markup_word} [{num}] {nodeid} - {reason}")
1352+
elif lineno is not None:
13481353
lines.append(f"{markup_word} [{num}] {fspath}:{lineno}: {reason}")
13491354
else:
13501355
lines.append(f"{markup_word} [{num}] {fspath}: {reason}")
@@ -1577,9 +1582,9 @@ def _get_line_with_reprcrash_message(
15771582

15781583
def _folded_skips(
15791584
startpath: Path,
1580-
skipped: Sequence[CollectReport],
1581-
) -> list[tuple[int, str, int | None, str]]:
1582-
d: dict[tuple[str, int | None, str], list[CollectReport]] = {}
1585+
skipped: Sequence[BaseReport],
1586+
) -> list[tuple[int, str, int | None, str, BaseReport | None]]:
1587+
d: dict[tuple[str, int | None, str], list[BaseReport]] = {}
15831588
for event in skipped:
15841589
assert event.longrepr is not None
15851590
assert isinstance(event.longrepr, tuple), (event, event.longrepr)
@@ -1600,9 +1605,10 @@ def _folded_skips(
16001605
else:
16011606
key = (fspath, lineno, reason)
16021607
d.setdefault(key, []).append(event)
1603-
values: list[tuple[int, str, int | None, str]] = []
1608+
values: list[tuple[int, str, int | None, str, BaseReport | None]] = []
16041609
for key, events in d.items():
1605-
values.append((len(events), *key))
1610+
single_report = events[0] if len(events) == 1 else None
1611+
values.append((len(events), *key, single_report))
16061612
return values
16071613

16081614

testing/test_mark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ def test(param):
10841084
[
10851085
"* collected 1 item",
10861086
"test_paramset_empty_no_idfunc* SKIPPED *",
1087-
"SKIPPED [1] test_paramset_empty_no_idfunc.py:5: got empty parameter set for (param)",
1087+
"SKIPPED [[]1[]] test_paramset_empty_no_idfunc.py::test[[]NOTSET[]] - got empty parameter set for (param)",
10881088
"*= 1 skipped in *",
10891089
]
10901090
)

testing/test_reports.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,11 @@ def test_skip(fixA, fixB):
472472
assert "ERROR at teardown" not in out
473473

474474
@pytest.mark.parametrize(
475-
"use_item_location, skip_file_location",
476-
[(True, "test_it.py"), (False, "runner.py")],
475+
"use_item_location",
476+
[True, False],
477477
)
478478
def test_exception_group_skips_use_item_location(
479-
self, pytester: Pytester, use_item_location: bool, skip_file_location: str
479+
self, pytester: Pytester, use_item_location: bool
480480
):
481481
"""
482482
Regression for #13537:
@@ -508,8 +508,8 @@ def test_both(fix_item1, fix_item2):
508508
out = result.stdout.str()
509509
# Both reasons should appear
510510
assert "A" and "B" in out
511-
# Crucially, the skip should be attributed to the test item, not teardown
512-
assert skip_file_location in out
511+
# The short summary should identify the skipped test item.
512+
assert "SKIPPED [1] test_it.py::test_both - A; B" in out
513513

514514

515515
class TestHooks:

testing/test_skipping.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,17 @@ def test_func2():
378378
[
379379
(
380380
["-rs"],
381-
["SKIPPED [1] test_sample.py:2: unconditional skip", "*1 skipped*"],
381+
[
382+
"SKIPPED [[]1[]] test_sample.py::test_skip_location - unconditional skip",
383+
"*1 skipped*",
384+
],
382385
),
383386
(
384387
["-rs", "--runxfail"],
385-
["SKIPPED [1] test_sample.py:2: unconditional skip", "*1 skipped*"],
388+
[
389+
"SKIPPED [[]1[]] test_sample.py::test_skip_location - unconditional skip",
390+
"*1 skipped*",
391+
],
386392
),
387393
],
388394
)
@@ -1009,9 +1015,9 @@ def doskip(reason):
10091015
result = pytester.runpytest("-rs")
10101016
result.stdout.fnmatch_lines_random(
10111017
[
1012-
"SKIPPED [[]1[]] test_one.py:7: setup function",
1013-
"SKIPPED [[]1[]] helpers.py:4: test method",
1014-
"SKIPPED [[]1[]] test_one.py:14: via_decorator",
1018+
"SKIPPED [[]1[]] test_one.py::test_func - setup function",
1019+
"SKIPPED [[]1[]] test_one.py::TestClass::test_method - test method",
1020+
"SKIPPED [[]1[]] test_one.py::TestClass::test_deco - via_decorator",
10151021
]
10161022
)
10171023
assert result.ret == 0
@@ -1426,7 +1432,7 @@ def test_pass():
14261432
)
14271433
result = pytester.runpytest("-rs", "tests/test_1.py", "--rootdir=tests")
14281434
result.stdout.fnmatch_lines(
1429-
["SKIPPED [[]1[]] tests/test_1.py:2: unconditional skip"]
1435+
["SKIPPED [[]1[]] tests/test_1.py::test_pass - unconditional skip"]
14301436
)
14311437

14321438

@@ -1447,7 +1453,7 @@ def arg():
14471453
)
14481454
result = pytester.runpytest("-rs", "tests/test_1.py", "--rootdir=tests")
14491455
result.stdout.fnmatch_lines(
1450-
["SKIPPED [[]1[]] tests/test_1.py:2: Fixture conditional skip"]
1456+
["SKIPPED [[]1[]] tests/test_1.py::test_pass - Fixture conditional skip"]
14511457
)
14521458

14531459

testing/test_subtests.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_bar(subtests):
166166
[
167167
"test_*.py .s * [[]100%[]]",
168168
"*=== short test summary info ===*",
169-
"SKIPPED [[]1[]] test_skip.py:9: skip test_bar",
169+
"SKIPPED [[]1[]] test_skip.py::test_bar - skip test_bar",
170170
"* 1 passed, 1 skipped in *",
171171
]
172172
)
@@ -179,9 +179,9 @@ def test_bar(subtests):
179179
"*.py::test_bar SUBSKIPPED[[]bar subtest[]] (skip bar subtest) * [[]100%[]]",
180180
"*.py::test_bar SKIPPED (skip test_bar) * [[]100%[]]",
181181
"*=== short test summary info ===*",
182-
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py:*: skip foo subtest",
183-
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py:*: skip bar subtest",
184-
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py:*: skip test_bar",
182+
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py::test_foo - skip foo subtest",
183+
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py::test_bar - skip bar subtest",
184+
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py::test_bar - skip test_bar",
185185
"* 1 passed, 3 skipped in *",
186186
]
187187
)
@@ -204,10 +204,10 @@ def test_bar(subtests):
204204
result.stdout.no_fnmatch_line("*.py::test_foo SUBPASSED[[]foo subtest[]]*")
205205
result.stdout.no_fnmatch_line("*.py::test_bar SUBPASSED[[]bar subtest[]]*")
206206
result.stdout.no_fnmatch_line(
207-
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py:*: skip foo subtest"
207+
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py::test_foo - skip foo subtest"
208208
)
209209
result.stdout.no_fnmatch_line(
210-
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py:*: skip test_bar"
210+
"SUBSKIPPED[[]foo subtest[]] [[]1[]] *.py::test_bar - skip test_bar"
211211
)
212212

213213

@@ -584,7 +584,9 @@ def test_foo(self):
584584
)
585585
result = pytester.runpytest("-v", "-rsf")
586586
result.stdout.fnmatch_lines(
587-
["SKIPPED [1] test_only_original_skip_is_called.py:6: skip this test"]
587+
[
588+
"SKIPPED [[]1[]] test_only_original_skip_is_called.py::T::test_foo - skip this test"
589+
]
588590
)
589591

590592
def test_skip_with_failure(
@@ -623,7 +625,7 @@ def test_foo(self):
623625
"*.py::T::test_foo SUBSKIPPED[[]subtest 1[]] (skip subtest 1) * [[]100%[]]",
624626
"*.py::T::test_foo SUBFAILED[[]subtest 2[]] * [[]100%[]]",
625627
"*.py::T::test_foo PASSED * [[]100%[]]",
626-
"SUBSKIPPED[[]subtest 1[]] [[]1[]] *.py:*: skip subtest 1",
628+
"SUBSKIPPED[[]subtest 1[]] [[]1[]] *.py::T::test_foo - skip subtest 1",
627629
"SUBFAILED[[]subtest 2[]] *.py::T::test_foo - AssertionError: fail subtest 2",
628630
"* 1 failed, 1 passed, 1 skipped in *",
629631
]
@@ -649,7 +651,7 @@ def test_foo(self):
649651
"*.py::T::test_foo SUBSKIPPED[[]subtest 1[]] (skip subtest 1) * [[]100%[]]"
650652
)
651653
result.stdout.no_fnmatch_line(
652-
"SUBSKIPPED[[]subtest 1[]] [[]1[]] *.py:*: skip subtest 1"
654+
"SUBSKIPPED[[]subtest 1[]] [[]1[]] *.py::T::test_foo - skip subtest 1"
653655
)
654656

655657
def test_msg_not_a_string(

testing/test_terminal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ def test():
11801180
"""
11811181
)
11821182
result = pytester.runpytest("-rsS")
1183-
expected = "SKIPPED [1] test_summary_s_alias.py:3: unconditional skip"
1183+
expected = "SKIPPED [1] test_summary_s_alias.py::test - unconditional skip"
11841184
result.stdout.fnmatch_lines([expected])
11851185
assert result.stdout.lines.count(expected) == 1
11861186

@@ -2544,11 +2544,12 @@ class X:
25442544

25452545
values = _folded_skips(Path.cwd(), [ev1, ev2, ev3])
25462546
assert len(values) == 1
2547-
num, fspath, lineno_, reason = values[0]
2547+
num, fspath, lineno_, reason, single_report = values[0]
25482548
assert num == 3
25492549
assert fspath == path
25502550
assert lineno_ == lineno
25512551
assert reason == message
2552+
assert single_report is None
25522553

25532554

25542555
def test_line_with_reprcrash(monkeypatch: MonkeyPatch) -> None:

0 commit comments

Comments
 (0)