Fix sequences being shortened even with `-vv` verbosity.

Fix #11777
This commit is contained in:
Kenny Y 2025-01-26 09:20:04 -03:00 committed by Bruno Oliveira
parent 6c9939b08b
commit d471aef984
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1 @@
Fixed issue where sequences were still being shortened even with ``-vv`` verbosity.

View File

@ -28,6 +28,7 @@ from typing import TYPE_CHECKING
from _pytest._io.saferepr import DEFAULT_REPR_MAX_SIZE
from _pytest._io.saferepr import saferepr
from _pytest._io.saferepr import saferepr_unlimited
from _pytest._version import version
from _pytest.assertion import util
from _pytest.config import Config
@ -433,6 +434,8 @@ def _saferepr(obj: object) -> str:
return obj.__name__
maxsize = _get_maxsize_for_saferepr(util._config)
if not maxsize:
return saferepr_unlimited(obj).replace("\n", "\\n")
return saferepr(obj, maxsize=maxsize).replace("\n", "\\n")

View File

@ -2617,6 +2617,35 @@ def test_short_summary_with_verbose(
)
def test_full_sequence_print_with_vv(
monkeypatch: MonkeyPatch, pytester: Pytester
) -> None:
"""Do not truncate sequences in summaries with -vv (#11777)."""
monkeypatch.setattr(_pytest.terminal, "running_on_ci", lambda: False)
pytester.makepyfile(
"""
def test_len_list():
l = list(range(10))
assert len(l) == 9
def test_len_dict():
d = dict(zip(range(10), range(10)))
assert len(d) == 9
"""
)
result = pytester.runpytest("-vv")
assert result.ret == 1
result.stdout.fnmatch_lines(
[
"*short test summary info*",
f"*{list(range(10))}*",
f"*{dict(zip(range(10), range(10)))}*",
]
)
def test_force_short_summary(monkeypatch: MonkeyPatch, pytester: Pytester) -> None:
monkeypatch.setattr(_pytest.terminal, "running_on_ci", lambda: False)