Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functional tests: fix automatic ref updating #9690

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions pylint/testutils/functional/lint_module_output_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import csv
import os

from pylint.testutils.lint_module_test import LintModuleTest, MessageCounter
from pylint.testutils.output_line import OutputLine
from pylint.testutils.lint_module_test import LintModuleTest


class LintModuleOutputUpdate(LintModuleTest):
Expand All @@ -24,20 +23,19 @@

csv.register_dialect("test", TestDialect)

def _check_output_text(
self,
_: MessageCounter,
expected_output: list[OutputLine],
actual_output: list[OutputLine],
) -> None:
def _runTest(self) -> None:
"""Overwrite or remove the expected output file based on actual output."""
# Remove the expected file if no output is actually emitted and a file exists
if not actual_output:
if os.path.exists(self._test_file.expected_output):
os.remove(self._test_file.expected_output)
return
# Write file with expected output
with open(self._test_file.expected_output, "w", encoding="utf-8") as f:
writer = csv.writer(f, dialect="test")
for line in actual_output:
writer.writerow(line.to_csv())
try:
super()._runTest()
finally:
actual_messages, actual_output = self._get_actual()

Check warning on line 31 in pylint/testutils/functional/lint_module_output_update.py

View workflow job for this annotation

GitHub Actions / pylint

W0612

Unused variable 'actual_messages'
# Remove the expected file if no output is actually emitted and a file exists
if not actual_output:
if os.path.exists(self._test_file.expected_output):
os.remove(self._test_file.expected_output)
return

Check warning on line 36 in pylint/testutils/functional/lint_module_output_update.py

View workflow job for this annotation

GitHub Actions / pylint

W0134

'return' shadowed by the 'finally' clause.

Check warning on line 36 in pylint/testutils/functional/lint_module_output_update.py

View workflow job for this annotation

GitHub Actions / pylint

W0150

return statement in finally block may swallow exception
# Write file with expected output
with open(self._test_file.expected_output, "w", encoding="utf-8") as f:
writer = csv.writer(f, dialect="test")
for line in actual_output:
writer.writerow(line.to_csv())
Loading