From 999e7c65417f1e97fc89bf66e0da4c5cd84442ec Mon Sep 17 00:00:00 2001 From: Matthew Duck Date: Mon, 19 Sep 2016 14:19:34 +0100 Subject: [PATCH] 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. --- _pytest/assertion/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/_pytest/assertion/__init__.py b/_pytest/assertion/__init__.py index fd1ebe2c1..e7f0e58ed 100644 --- a/_pytest/assertion/__init__.py +++ b/_pytest/assertion/__init__.py @@ -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":