Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.3.x] Fix sequences being shortened even with -vv verbosity. #13163

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/11777.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue where sequences were still being shortened even with ``-vv`` verbosity.
3 changes: 3 additions & 0 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

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
Expand Down Expand Up @@ -432,6 +433,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")


Expand Down
29 changes: 29 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,35 @@ def test():
)


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)))}*",
]
)


@pytest.mark.parametrize(
"seconds, expected",
[
Expand Down
Loading