Skip to content

Commit a17e708

Browse files
With -vv, display the full skip/xfail reason instead of "..." (#9537)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 382e3d3 commit a17e708

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

changelog/9536.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
When ``-vv`` is given on command line, show skipping and xfail reasons in full instead of truncating them to fit the terminal width.

src/_pytest/terminal.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,21 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
542542
if not running_xdist:
543543
self.write_ensure_prefix(line, word, **markup)
544544
if rep.skipped or hasattr(report, "wasxfail"):
545-
available_width = (
546-
(self._tw.fullwidth - self._tw.width_of_current_line)
547-
- len(" [100%]")
548-
- 1
549-
)
550545
reason = _get_raw_skip_reason(rep)
551-
reason_ = _format_trimmed(" ({})", reason, available_width)
552-
if reason and reason_ is not None:
553-
self._tw.write(reason_)
546+
if self.config.option.verbose < 2:
547+
available_width = (
548+
(self._tw.fullwidth - self._tw.width_of_current_line)
549+
- len(" [100%]")
550+
- 1
551+
)
552+
formatted_reason = _format_trimmed(
553+
" ({})", reason, available_width
554+
)
555+
else:
556+
formatted_reason = f" ({reason})"
557+
558+
if reason and formatted_reason is not None:
559+
self._tw.write(formatted_reason)
554560
if self._show_progress_info:
555561
self._write_progress_information_filling_space()
556562
else:

testing/test_terminal.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,21 +385,55 @@ def test_9():
385385
386386
def test_10():
387387
pytest.xfail("It's 🕙 o'clock")
388+
389+
@pytest.mark.skip(
390+
reason="cannot do foobar because baz is missing due to I don't know what"
391+
)
392+
def test_long_skip():
393+
pass
394+
395+
@pytest.mark.xfail(
396+
reason="cannot do foobar because baz is missing due to I don't know what"
397+
)
398+
def test_long_xfail():
399+
print(1 / 0)
388400
"""
389401
)
402+
403+
common_output = [
404+
"test_verbose_skip_reason.py::test_1 SKIPPED (123) *",
405+
"test_verbose_skip_reason.py::test_2 XPASS (456) *",
406+
"test_verbose_skip_reason.py::test_3 XFAIL (789) *",
407+
"test_verbose_skip_reason.py::test_4 XFAIL *",
408+
"test_verbose_skip_reason.py::test_5 SKIPPED (unconditional skip) *",
409+
"test_verbose_skip_reason.py::test_6 XPASS *",
410+
"test_verbose_skip_reason.py::test_7 SKIPPED *",
411+
"test_verbose_skip_reason.py::test_8 SKIPPED (888 is great) *",
412+
"test_verbose_skip_reason.py::test_9 XFAIL *",
413+
"test_verbose_skip_reason.py::test_10 XFAIL (It's 🕙 o'clock) *",
414+
]
415+
390416
result = pytester.runpytest("-v")
391417
result.stdout.fnmatch_lines(
392-
[
393-
"test_verbose_skip_reason.py::test_1 SKIPPED (123) *",
394-
"test_verbose_skip_reason.py::test_2 XPASS (456) *",
395-
"test_verbose_skip_reason.py::test_3 XFAIL (789) *",
396-
"test_verbose_skip_reason.py::test_4 XFAIL *",
397-
"test_verbose_skip_reason.py::test_5 SKIPPED (unconditional skip) *",
398-
"test_verbose_skip_reason.py::test_6 XPASS *",
399-
"test_verbose_skip_reason.py::test_7 SKIPPED *",
400-
"test_verbose_skip_reason.py::test_8 SKIPPED (888 is great) *",
401-
"test_verbose_skip_reason.py::test_9 XFAIL *",
402-
"test_verbose_skip_reason.py::test_10 XFAIL (It's 🕙 o'clock) *",
418+
common_output
419+
+ [
420+
"test_verbose_skip_reason.py::test_long_skip SKIPPED (cannot *...) *",
421+
"test_verbose_skip_reason.py::test_long_xfail XFAIL (cannot *...) *",
422+
]
423+
)
424+
425+
result = pytester.runpytest("-vv")
426+
result.stdout.fnmatch_lines(
427+
common_output
428+
+ [
429+
(
430+
"test_verbose_skip_reason.py::test_long_skip SKIPPED"
431+
" (cannot do foobar because baz is missing due to I don't know what) *"
432+
),
433+
(
434+
"test_verbose_skip_reason.py::test_long_xfail XFAIL"
435+
" (cannot do foobar because baz is missing due to I don't know what) *"
436+
),
403437
]
404438
)
405439

0 commit comments

Comments
 (0)