Skip to content
Open
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/5675.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When `--showlocals` is enabled, function arguments are no longer displayed in a separate block because they are already included in the locals output.
3 changes: 2 additions & 1 deletion src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,8 @@ def toterminal(self, tw: TerminalWriter) -> None:
self.reprlocals.toterminal(tw, indent=" " * 8)
return

if self.reprfuncargs:
# Locals already include the arguments; skip the separate block.
if self.reprfuncargs and self.reprlocals is None:
self.reprfuncargs.toterminal(tw)

self._write_entry_lines(tw)
Expand Down
27 changes: 27 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,33 @@ def test_showlocals_short():
]
)

def test_showlocals_no_duplicate_funcargs(self, pytester: Pytester) -> None:
"""Helper params must not render twice with --showlocals (#5675)."""
p1 = pytester.makepyfile(
"""
class LargeRepr:
def __repr__(self):
return "X" * 10000

def helper(data, flag):
assert flag is False

def test_failure():
helper(LargeRepr(), True)
"""
)
# Without --showlocals the funcargs block stays (truncated).
result = pytester.runpytest(p1)
result.stdout.fnmatch_lines(["data = X*"])
# With --showlocals params show once, in the padded locals block.
result = pytester.runpytest(p1, "--showlocals")
result.stdout.no_fnmatch_line("data = X*")
result.stdout.fnmatch_lines(["data *= X*"])
# Same at higher verbosity; locals keep their existing behavior.
result = pytester.runpytest(p1, "--showlocals", "-vv")
result.stdout.no_fnmatch_line("data = X*")
result.stdout.fnmatch_lines(["data *= X*"])

@pytest.fixture
def verbose_testfile(self, pytester: Pytester) -> Path:
return pytester.makepyfile(
Expand Down
Loading