From a79cfe90a5997ee6e3849c5af1107ba0b3651ab4 Mon Sep 17 00:00:00 2001 From: Vladyslav Rachek Date: Sun, 12 Jan 2020 01:18:27 +0100 Subject: [PATCH 1/4] Initial proposal to #6267, change truncation message Ref. https://github.com/pytest-dev/pytest/issues/6267 --- src/_pytest/assertion/truncate.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/_pytest/assertion/truncate.py b/src/_pytest/assertion/truncate.py index d97b05b441e..034ae77a5c6 100644 --- a/src/_pytest/assertion/truncate.py +++ b/src/_pytest/assertion/truncate.py @@ -40,6 +40,8 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None): Truncates to either 8 lines, or 640 characters - whichever the input reaches first. The remaining lines will be replaced by a usage message. + + Check https://github.com/pytest-dev/pytest/issues/6267 for corner cases """ if max_lines is None: @@ -48,6 +50,7 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None): max_chars = DEFAULT_MAX_CHARS # Check if truncation required + input_char_count = len("".join(input_lines)) if len(input_lines) <= max_lines and input_char_count <= max_chars: return input_lines @@ -62,12 +65,18 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None): # Append useful message to explanation truncated_line_count = len(input_lines) - len(truncated_explanation) - truncated_line_count += 1 # Account for the part-truncated final line msg = "...Full output truncated" + last_truncated = not ( + input_lines[len(truncated_explanation) - 1] in truncated_explanation[-1] + ) if truncated_line_count == 1: - msg += " ({} line hidden)".format(truncated_line_count) + msg += " ({} line hidden".format(truncated_line_count) + else: + msg += " ({} lines hidden".format(truncated_line_count) + if last_truncated: + msg += ",1 truncated)" else: - msg += " ({} lines hidden)".format(truncated_line_count) + msg += ")" msg += ", {}".format(USAGE_MSG) truncated_explanation.extend(["", str(msg)]) return truncated_explanation From 937e0e2da180265e04944e40412b1b97811dc5a4 Mon Sep 17 00:00:00 2001 From: Vladyslav Rachek Date: Wed, 15 Jan 2020 01:46:37 +0100 Subject: [PATCH 2/4] Add changelog entry --- changelog/6267.feature.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog/6267.feature.rst diff --git a/changelog/6267.feature.rst b/changelog/6267.feature.rst new file mode 100644 index 00000000000..268ebc24130 --- /dev/null +++ b/changelog/6267.feature.rst @@ -0,0 +1,2 @@ +When output is close to truncation limit, we now write 'N lines hidden [1 truncated]', +instead of 'N+1 lines hidden' - last line which we show isn't really hidden always, neither it's always really truncated. From 8b521ba51644c6e69dfd5865ce610f749514553e Mon Sep 17 00:00:00 2001 From: Vladyslav Rachek <36896640+erheron@users.noreply.github.com> Date: Wed, 19 Feb 2020 22:11:20 +0100 Subject: [PATCH 3/4] Update src/_pytest/assertion/truncate.py Co-Authored-By: Daniel Hahler --- src/_pytest/assertion/truncate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/_pytest/assertion/truncate.py b/src/_pytest/assertion/truncate.py index 034ae77a5c6..a32f0721ae6 100644 --- a/src/_pytest/assertion/truncate.py +++ b/src/_pytest/assertion/truncate.py @@ -50,7 +50,6 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None): max_chars = DEFAULT_MAX_CHARS # Check if truncation required - input_char_count = len("".join(input_lines)) if len(input_lines) <= max_lines and input_char_count <= max_chars: return input_lines From b62aad0c1a0e7e3822c673662b65781efd0fff73 Mon Sep 17 00:00:00 2001 From: Vladyslav Rachek Date: Wed, 19 Feb 2020 22:12:46 +0100 Subject: [PATCH 4/4] Add missing space --- src/_pytest/assertion/truncate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/assertion/truncate.py b/src/_pytest/assertion/truncate.py index a32f0721ae6..dc8fd3c4c2e 100644 --- a/src/_pytest/assertion/truncate.py +++ b/src/_pytest/assertion/truncate.py @@ -73,7 +73,7 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None): else: msg += " ({} lines hidden".format(truncated_line_count) if last_truncated: - msg += ",1 truncated)" + msg += ", 1 truncated)" else: msg += ")" msg += ", {}".format(USAGE_MSG)