Tidy formatting of assertion truncation

Part two of https://github.com/pytest-dev/pytest/issues/1512. Update the format
of the truncation message to help make it clear that pytest truncates the
entire assertion output when verbosity < 2.
This commit is contained in:
Matthew Duck 2016-09-19 14:19:34 +01:00
parent dd64d823b9
commit 999e7c6541
1 changed files with 11 additions and 4 deletions

View File

@ -131,14 +131,21 @@ def pytest_runtest_setup(item):
config=item.config, op=op, left=left, right=right)
for new_expl in hook_result:
if new_expl:
# Truncate lines if required
if (sum(len(p) for p in new_expl[1:]) > 80*8 and
item.config.option.verbose < 2 and
not _running_on_ci()):
show_max = 10
truncated_lines = len(new_expl) - show_max
new_expl[show_max:] = [py.builtin._totext(
'Detailed information truncated (%d more lines)'
', use "-vv" to show' % truncated_lines)]
truncated_count = len(new_expl) - show_max
new_expl[show_max - 1] += " ..."
new_expl[show_max:] = [
py.builtin._totext(""),
py.builtin._totext('...Full output truncated (%d more lines)'
', use "-vv" to show' % truncated_count
),
]
new_expl = [line.replace("\n", "\\n") for line in new_expl]
res = py.builtin._totext("\n~").join(new_expl)
if item.config.getvalue("assertmode") == "rewrite":