From 785c6291d56f4f043c0ee9d1c835a8241ed67d5a Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Thu, 15 Dec 2022 23:04:12 +0100 Subject: [PATCH] [testutil] More information in output for functional test fail (#7948) In order to help when the target interpreter is not installed locally and you can't update automatically yourself (pypy/old interpreters like python 3.7). Done for: Refs #7945 --- pylint/testutils/lint_module_test.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pylint/testutils/lint_module_test.py b/pylint/testutils/lint_module_test.py index 0d3dbb0bf4..17decf8a5f 100644 --- a/pylint/testutils/lint_module_test.py +++ b/pylint/testutils/lint_module_test.py @@ -287,12 +287,7 @@ def error_msg_for_unequal_output( ) -> str: missing = set(expected_lines) - set(received_lines) unexpected = set(received_lines) - set(expected_lines) - error_msg = ( - f"Wrong output for '{self._test_file.base}.txt':\n" - "You can update the expected output automatically with: '" - f"python tests/test_functional.py {UPDATE_OPTION} -k " - f'"test_functional[{self._test_file.base}]"\'\n\n' - ) + error_msg = f"Wrong output for '{self._test_file.base}.txt':" sort_by_line_number = operator.attrgetter("lineno") if missing: error_msg += "\n- Missing lines:\n" @@ -302,6 +297,17 @@ def error_msg_for_unequal_output( error_msg += "\n- Unexpected lines:\n" for line in sorted(unexpected, key=sort_by_line_number): error_msg += f"{line}\n" + error_msg += ( + "\nYou can update the expected output automatically with:\n'" + f"python tests/test_functional.py {UPDATE_OPTION} -k " + f'"test_functional[{self._test_file.base}]"\'\n\n' + "Here's the update text in case you can't:\n" + ) + expected_csv = StringIO() + writer = csv.writer(expected_csv, dialect="test") + for line in sorted(received_lines, key=sort_by_line_number): + writer.writerow(line.to_csv()) + error_msg += expected_csv.getvalue() return error_msg def _check_output_text(