Skip to content

Commit 10f84e1

Browse files
committed
Add --force-short-summary option and extend sequence printing with -vv
1 parent 28e1e25 commit 10f84e1

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

changelog/12713.feature.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Add `--force-short-summary` option to force condensed summary output regardless of verbosity level
2+
3+
Adds ability to still see condensed summary output of failures for quick reference in log files from job outputs. Especially useful if non-condensed output is very verbose.
4+
5+
Also includes full fix for :issue:`11777` where sequences were still being shortened even with `-vv` verbosity.

src/_pytest/assertion/rewrite.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from _pytest._io.saferepr import DEFAULT_REPR_MAX_SIZE
3030
from _pytest._io.saferepr import saferepr
31+
from _pytest._io.saferepr import saferepr_unlimited
3132
from _pytest._version import version
3233
from _pytest.assertion import util
3334
from _pytest.config import Config
@@ -433,6 +434,8 @@ def _saferepr(obj: object) -> str:
433434
return obj.__name__
434435

435436
maxsize = _get_maxsize_for_saferepr(util._config)
437+
if not maxsize:
438+
return saferepr_unlimited(obj).replace("\n", "\\n")
436439
return saferepr(obj, maxsize=maxsize).replace("\n", "\\n")
437440

438441

src/_pytest/terminal.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ def pytest_addoption(parser: Parser) -> None:
161161
default=True,
162162
help="Do not fold skipped tests in short summary.",
163163
)
164+
group._addoption(
165+
"--force-short-summary",
166+
action="store_true",
167+
dest="force_short_summary",
168+
default=False,
169+
help="Force condensed summary output regardless of verbosity level.",
170+
)
164171
group._addoption(
165172
"-q",
166173
"--quiet",
@@ -1467,7 +1474,9 @@ def _get_line_with_reprcrash_message(
14671474
except AttributeError:
14681475
pass
14691476
else:
1470-
if running_on_ci() or config.option.verbose >= 2:
1477+
if (
1478+
running_on_ci() or config.option.verbose >= 2
1479+
) and not config.option.force_short_summary:
14711480
msg = f" - {msg}"
14721481
else:
14731482
available_width = tw.fullwidth - line_width

testing/test_terminal.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,51 @@ def test():
25202520
)
25212521

25222522

2523+
def test_full_sequence_print_with_vv(
2524+
monkeypatch: MonkeyPatch, pytester: Pytester
2525+
) -> None:
2526+
monkeypatch.setattr(_pytest.terminal, "running_on_ci", lambda: False)
2527+
2528+
pytester.makepyfile(
2529+
"""
2530+
def test_len_list():
2531+
l = list(range(10))
2532+
assert len(l) == 9
2533+
2534+
def test_len_dict():
2535+
d = dict(zip(range(10), range(10)))
2536+
assert len(d) == 9
2537+
"""
2538+
)
2539+
2540+
result = pytester.runpytest("-vv")
2541+
assert result.ret == 1
2542+
result.stdout.fnmatch_lines(
2543+
[
2544+
"*short test summary info*",
2545+
f"*{list(range(10))}*",
2546+
f"*{dict(zip(range(10), range(10)))}*",
2547+
]
2548+
)
2549+
2550+
2551+
def test_force_short_summary(monkeypatch: MonkeyPatch, pytester: Pytester) -> None:
2552+
monkeypatch.setattr(_pytest.terminal, "running_on_ci", lambda: False)
2553+
2554+
pytester.makepyfile(
2555+
"""
2556+
def test():
2557+
assert "a\\n" * 10 == ""
2558+
"""
2559+
)
2560+
2561+
result = pytester.runpytest("-vv", "--force-short-summary")
2562+
assert result.ret == 1
2563+
result.stdout.fnmatch_lines(
2564+
["*short test summary info*", "*AssertionError: assert 'a\\na\\na\\na..."]
2565+
)
2566+
2567+
25232568
@pytest.mark.parametrize(
25242569
"seconds, expected",
25252570
[

0 commit comments

Comments
 (0)