Skip to content

Commit

Permalink
[testutil] More information in output for functional test fail
Browse files Browse the repository at this point in the history
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 pylint-dev#7945
  • Loading branch information
Pierre-Sassoulas committed Dec 15, 2022
1 parent 62232b3 commit 3f778f9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pylint/testutils/lint_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down

0 comments on commit 3f778f9

Please sign in to comment.