Skip to content

Commit 999e7c6

Browse files
committed
Tidy formatting of assertion truncation
Part two of pytest-dev#1512. Update the format of the truncation message to help make it clear that pytest truncates the entire assertion output when verbosity < 2.
1 parent dd64d82 commit 999e7c6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

_pytest/assertion/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,21 @@ def callbinrepr(op, left, right):
131131
config=item.config, op=op, left=left, right=right)
132132
for new_expl in hook_result:
133133
if new_expl:
134+
135+
# Truncate lines if required
134136
if (sum(len(p) for p in new_expl[1:]) > 80*8 and
135137
item.config.option.verbose < 2 and
136138
not _running_on_ci()):
137139
show_max = 10
138-
truncated_lines = len(new_expl) - show_max
139-
new_expl[show_max:] = [py.builtin._totext(
140-
'Detailed information truncated (%d more lines)'
141-
', use "-vv" to show' % truncated_lines)]
140+
truncated_count = len(new_expl) - show_max
141+
new_expl[show_max - 1] += " ..."
142+
new_expl[show_max:] = [
143+
py.builtin._totext(""),
144+
py.builtin._totext('...Full output truncated (%d more lines)'
145+
', use "-vv" to show' % truncated_count
146+
),
147+
]
148+
142149
new_expl = [line.replace("\n", "\\n") for line in new_expl]
143150
res = py.builtin._totext("\n~").join(new_expl)
144151
if item.config.getvalue("assertmode") == "rewrite":

0 commit comments

Comments
 (0)