code: do not truncate args when running with -vvv (#12241)

Related to #2871.
This commit is contained in:
Michael Vogt
2024-06-03 14:11:41 +02:00
committed by GitHub
parent 177f2ae6c4
commit 7be95f9b30
6 changed files with 73 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ import re
import sys
import textwrap
from typing import Any
from typing import cast
from typing import TYPE_CHECKING
import _pytest._code
@@ -712,6 +713,29 @@ raise ValueError()
assert full_reprlocals.lines
assert full_reprlocals.lines[0] == "l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
def test_repr_args_not_truncated(self, importasmod) -> None:
mod = importasmod(
"""
def func1(m):
raise ValueError("hello\\nworld")
"""
)
excinfo = pytest.raises(ValueError, mod.func1, "m" * 500)
excinfo.traceback = excinfo.traceback.filter(excinfo)
entry = excinfo.traceback[-1]
p = FormattedExcinfo(funcargs=True, truncate_args=True)
reprfuncargs = p.repr_args(entry)
assert reprfuncargs is not None
arg1 = cast(str, reprfuncargs.args[0][1])
assert len(arg1) < 500
assert "..." in arg1
# again without truncate
p = FormattedExcinfo(funcargs=True, truncate_args=False)
reprfuncargs = p.repr_args(entry)
assert reprfuncargs is not None
assert reprfuncargs.args[0] == ("m", repr("m" * 500))
assert "..." not in cast(str, reprfuncargs.args[0][1])
def test_repr_tracebackentry_lines(self, importasmod) -> None:
mod = importasmod(
"""