diff --git a/doc/whatsnew/fragments/9059.bugfix b/doc/whatsnew/fragments/9059.bugfix new file mode 100644 index 0000000000..89bd611e51 --- /dev/null +++ b/doc/whatsnew/fragments/9059.bugfix @@ -0,0 +1,5 @@ +Prevented data loss in the linter stats for messages relating +to the linter itself (e.g. ``unknown-option-value``), fixing +problems with score, fail-on, etc. + +Closes #9059 diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index cecf4f195c..e21d8b5d97 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -1071,7 +1071,6 @@ def _check_astroid_module( def open(self) -> None: """Initialize counters.""" - self.stats = LinterStats() MANAGER.always_load_extensions = self.config.unsafe_load_any_extension MANAGER.max_inferable_values = self.config.limit_inference_results MANAGER.extension_package_whitelist.update(self.config.extension_pkg_allow_list) diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 914b2efbbd..7e4b4dfcca 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -41,7 +41,12 @@ from pylint.testutils import create_files from pylint.testutils._run import _Run as Run from pylint.typing import MessageLocationTuple -from pylint.utils import FileState, print_full_documentation, tokenize_module +from pylint.utils import ( + FileState, + LinterStats, + print_full_documentation, + tokenize_module, +) if os.name == "java": if os.name == "nt": @@ -1030,6 +1035,8 @@ def test_by_module_statement_value(initialized_linter: PyLinter) -> None: by_module_stats = linter.stats.by_module for module, module_stats in by_module_stats.items(): linter2 = initialized_linter + linter2.stats = LinterStats() + if module == "data": linter2.check([os.path.join(os.path.dirname(__file__), "data/__init__.py")]) else: diff --git a/tests/test_check_parallel.py b/tests/test_check_parallel.py index 0f363e32a0..f212df850b 100644 --- a/tests/test_check_parallel.py +++ b/tests/test_check_parallel.py @@ -382,6 +382,7 @@ def test_sequential_checkers_work(self) -> None: # now run the regular mode of checking files and check that, in this proc, we # collect the right data filepath = [single_file_container[0][1]] # get the filepath element + linter.stats = LinterStats() linter.check(filepath) assert { "input.similar1": { # module is the only change from previous diff --git a/tests/test_regr.py b/tests/test_regr.py index d927429435..19fc009a67 100644 --- a/tests/test_regr.py +++ b/tests/test_regr.py @@ -20,6 +20,7 @@ from pylint import testutils from pylint.lint.pylinter import PyLinter +from pylint.utils.linterstats import LinterStats REGR_DATA = join(dirname(abspath(__file__)), "regrtest_data") sys.path.insert(1, REGR_DATA) @@ -116,6 +117,7 @@ def test_check_package___init__(finalize_linter: PyLinter) -> None: assert sorted(checked) == sorted(filename) os.chdir(join(REGR_DATA, "package")) + finalize_linter.stats = LinterStats() finalize_linter.check(["__init__"]) checked = list(finalize_linter.stats.by_module.keys()) assert checked == ["__init__"] diff --git a/tests/test_self.py b/tests/test_self.py index 09a1ccfc3e..159d3960e1 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -768,6 +768,15 @@ def test_fail_on(self, fu_score: int, fo_msgs: str, fname: str, out: int) -> Non (["--disable=C0116", "--fail-on=C0116"], 16), # Ensure order does not matter (["--fail-on=C0116", "--disable=C0116"], 16), + # Message emitted by PyLinter itself + ( + [ + "--fail-on=unknown-option-value", + "--disable=all", + "--enable=unknown-option-value, trigger", + ], + 4, + ), ], ) def test_fail_on_edge_case(self, opts: list[str], out: int) -> None: