Skip to content

Commit a79cfe9

Browse files
committed
Initial proposal to pytest-dev#6267, change truncation message
Ref. pytest-dev#6267
1 parent b29ae03 commit a79cfe9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/_pytest/assertion/truncate.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None):
4040
4141
Truncates to either 8 lines, or 640 characters - whichever the input reaches
4242
first. The remaining lines will be replaced by a usage message.
43+
44+
Check https://github.com/pytest-dev/pytest/issues/6267 for corner cases
4345
"""
4446

4547
if max_lines is None:
@@ -48,6 +50,7 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None):
4850
max_chars = DEFAULT_MAX_CHARS
4951

5052
# Check if truncation required
53+
5154
input_char_count = len("".join(input_lines))
5255
if len(input_lines) <= max_lines and input_char_count <= max_chars:
5356
return input_lines
@@ -62,12 +65,18 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None):
6265

6366
# Append useful message to explanation
6467
truncated_line_count = len(input_lines) - len(truncated_explanation)
65-
truncated_line_count += 1 # Account for the part-truncated final line
6668
msg = "...Full output truncated"
69+
last_truncated = not (
70+
input_lines[len(truncated_explanation) - 1] in truncated_explanation[-1]
71+
)
6772
if truncated_line_count == 1:
68-
msg += " ({} line hidden)".format(truncated_line_count)
73+
msg += " ({} line hidden".format(truncated_line_count)
74+
else:
75+
msg += " ({} lines hidden".format(truncated_line_count)
76+
if last_truncated:
77+
msg += ",1 truncated)"
6978
else:
70-
msg += " ({} lines hidden)".format(truncated_line_count)
79+
msg += ")"
7180
msg += ", {}".format(USAGE_MSG)
7281
truncated_explanation.extend(["", str(msg)])
7382
return truncated_explanation

0 commit comments

Comments
 (0)