From 5c78ef125f16f1e3a194b0472aaa74f60e4f1392 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 29 Oct 2022 19:19:03 +0200 Subject: [PATCH] [perf] Use f-string instead of formatting for truncation message --- src/_pytest/assertion/truncate.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/_pytest/assertion/truncate.py b/src/_pytest/assertion/truncate.py index ce148dca0..df9fa90ba 100644 --- a/src/_pytest/assertion/truncate.py +++ b/src/_pytest/assertion/truncate.py @@ -62,13 +62,13 @@ def _truncate_explanation( # 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" - if truncated_line_count == 1: - msg += f" ({truncated_line_count} line hidden)" - else: - msg += f" ({truncated_line_count} lines hidden)" - msg += f", {USAGE_MSG}" - truncated_explanation.extend(["", str(msg)]) + truncated_explanation.extend( + [ + "", # Line break + f"...Full output truncated ({truncated_line_count} line" + f"{'' if truncated_line_count == 1 else 's'} hidden), {USAGE_MSG}", + ] + ) return truncated_explanation