@@ -40,6 +40,8 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None):
40
40
41
41
Truncates to either 8 lines, or 640 characters - whichever the input reaches
42
42
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
43
45
"""
44
46
45
47
if max_lines is None :
@@ -48,6 +50,7 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None):
48
50
max_chars = DEFAULT_MAX_CHARS
49
51
50
52
# Check if truncation required
53
+
51
54
input_char_count = len ("" .join (input_lines ))
52
55
if len (input_lines ) <= max_lines and input_char_count <= max_chars :
53
56
return input_lines
@@ -62,12 +65,18 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None):
62
65
63
66
# Append useful message to explanation
64
67
truncated_line_count = len (input_lines ) - len (truncated_explanation )
65
- truncated_line_count += 1 # Account for the part-truncated final line
66
68
msg = "...Full output truncated"
69
+ last_truncated = not (
70
+ input_lines [len (truncated_explanation ) - 1 ] in truncated_explanation [- 1 ]
71
+ )
67
72
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)"
69
78
else :
70
- msg += " ({} lines hidden)" . format ( truncated_line_count )
79
+ msg += ")"
71
80
msg += ", {}" .format (USAGE_MSG )
72
81
truncated_explanation .extend (["" , str (msg )])
73
82
return truncated_explanation
0 commit comments