From 9e345ba62ae8f5673750ccd68a08d15928885c41 Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Thu, 10 Nov 2022 18:00:00 -0800 Subject: [PATCH 01/15] Deduplicate module file paths to prevent redundant scans. Closes #6242 May also address #4053 --- doc/whatsnew/fragments/6242.bugfix | 5 +++++ pylint/lint/pylinter.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 doc/whatsnew/fragments/6242.bugfix diff --git a/doc/whatsnew/fragments/6242.bugfix b/doc/whatsnew/fragments/6242.bugfix new file mode 100644 index 0000000000..4337a0b59c --- /dev/null +++ b/doc/whatsnew/fragments/6242.bugfix @@ -0,0 +1,5 @@ +Maintain and reference a set of visited files while expanding the module files +from list of module directories, package names, and standalone files to +prevent duplicate scans. + +Closes #6242 diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 66455bfb10..2c9318713a 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -14,7 +14,7 @@ import traceback import warnings from collections import defaultdict -from collections.abc import Callable, Iterator, Sequence +from collections.abc import Callable, Iterator, MutableSet, Sequence from io import TextIOWrapper from pathlib import Path from re import Pattern @@ -878,8 +878,12 @@ def _iterate_file_descrs( The returned generator yield one item for each Python module that should be linted. """ + seen_filepaths: MutableSet[str] = set() # For deduplication of paths. for descr in self._expand_files(files_or_modules): name, filepath, is_arg = descr["name"], descr["path"], descr["isarg"] + if filepath in seen_filepaths: + continue + seen_filepaths.add(filepath) if self.should_analyze_file(name, filepath, is_argument=is_arg): yield FileItem(name, filepath, descr["basename"]) From 0538ffd992a14ed65d546dc40d56a84b16e05ce4 Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Fri, 11 Nov 2022 18:22:27 -0800 Subject: [PATCH 02/15] Use dict for 'expand_modules' result rather than list. With 'path' as the key, we get deduplication for free and do not need to reprocess the list for deduplication later. --- pylint/lint/expand_modules.py | 36 ++++++++++++--------------- pylint/lint/pylinter.py | 10 +++----- tests/lint/unittest_expand_modules.py | 36 ++++++++++++++------------- 3 files changed, 38 insertions(+), 44 deletions(-) diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py index 91887cd923..2b796e651b 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -66,11 +66,11 @@ def expand_modules( ignore_list: list[str], ignore_list_re: list[Pattern[str]], ignore_list_paths_re: list[Pattern[str]], -) -> tuple[list[ModuleDescriptionDict], list[ErrorDescriptionDict]]: +) -> tuple[dict[str, ModuleDescriptionDict], list[ErrorDescriptionDict]]: """Take a list of files/modules/packages and return the list of tuple (file, module name) which have to be actually checked. """ - result: list[ModuleDescriptionDict] = [] + result: dict[str, ModuleDescriptionDict] = {} errors: list[ErrorDescriptionDict] = [] path = sys.path.copy() @@ -120,15 +120,13 @@ def expand_modules( is_namespace = modutils.is_namespace(spec) is_directory = modutils.is_directory(spec) if not is_namespace: - result.append( - { - "path": filepath, - "name": modname, - "isarg": True, - "basepath": filepath, - "basename": modname, - } - ) + result[filepath] = { + "path": filepath, + "name": modname, + "isarg": True, + "basepath": filepath, + "basename": modname, + } has_init = ( not (modname.endswith(".__init__") or modname == "__init__") and os.path.basename(filepath) == "__init__.py" @@ -148,13 +146,11 @@ def expand_modules( subfilepath, is_namespace, path=additional_search_path ) submodname = ".".join(modpath) - result.append( - { - "path": subfilepath, - "name": submodname, - "isarg": False, - "basepath": filepath, - "basename": modname, - } - ) + result[subfilepath] = { + "path": subfilepath, + "name": submodname, + "isarg": False, + "basepath": filepath, + "basename": modname, + } return result, errors diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 218b404e3b..cfa932190f 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -14,7 +14,7 @@ import traceback import warnings from collections import defaultdict -from collections.abc import Callable, Iterator, MutableSet, Sequence +from collections.abc import Callable, Iterator, Sequence from io import TextIOWrapper from pathlib import Path from re import Pattern @@ -879,16 +879,12 @@ def _iterate_file_descrs( The returned generator yield one item for each Python module that should be linted. """ - seen_filepaths: MutableSet[str] = set() # For deduplication of paths. - for descr in self._expand_files(files_or_modules): + for descr in self._expand_files(files_or_modules).values(): name, filepath, is_arg = descr["name"], descr["path"], descr["isarg"] - if filepath in seen_filepaths: - continue - seen_filepaths.add(filepath) if self.should_analyze_file(name, filepath, is_argument=is_arg): yield FileItem(name, filepath, descr["basename"]) - def _expand_files(self, modules: Sequence[str]) -> list[ModuleDescriptionDict]: + def _expand_files(self, modules: Sequence[str]) -> dict[str, ModuleDescriptionDict]: """Get modules and errors from a list of modules and handle errors.""" result, errors = expand_modules( modules, diff --git a/tests/lint/unittest_expand_modules.py b/tests/lint/unittest_expand_modules.py index 1883db543f..a40df405d9 100644 --- a/tests/lint/unittest_expand_modules.py +++ b/tests/lint/unittest_expand_modules.py @@ -102,23 +102,26 @@ class Checker(BaseChecker): @pytest.mark.parametrize( "files_or_modules,expected", [ - ([__file__], [this_file]), + ([__file__], {this_file["path"]: this_file}), ( [str(Path(__file__).parent)], - [ - init_of_package, - test_caching, - test_pylinter, - test_utils, - this_file_from_init, - unittest_lint, - ], + { + module["path"]: module # pylint: disable=unsubscriptable-object + for module in ( + init_of_package, + test_caching, + test_pylinter, + test_utils, + this_file_from_init, + unittest_lint, + ) + }, ), ], ) @set_config(ignore_paths="") def test_expand_modules( - self, files_or_modules: list[str], expected: list[ModuleDescriptionDict] + self, files_or_modules: list[str], expected: dict[str, ModuleDescriptionDict] ) -> None: """Test expand_modules with the default value of ignore-paths.""" ignore_list: list[str] = [] @@ -129,25 +132,25 @@ def test_expand_modules( ignore_list_re, self.linter.config.ignore_paths, ) - modules.sort(key=lambda d: d["name"]) assert modules == expected assert not errors @pytest.mark.parametrize( "files_or_modules,expected", [ - ([__file__], []), + ([__file__], {}), ( [str(Path(__file__).parent)], - [ - init_of_package, - ], + { + module["path"]: module # pylint: disable=unsubscriptable-object + for module in (init_of_package,) + }, ), ], ) @set_config(ignore_paths=".*/lint/.*") def test_expand_modules_with_ignore( - self, files_or_modules: list[str], expected: list[ModuleDescriptionDict] + self, files_or_modules: list[str], expected: dict[str, ModuleDescriptionDict] ) -> None: """Test expand_modules with a non-default value of ignore-paths.""" ignore_list: list[str] = [] @@ -158,6 +161,5 @@ def test_expand_modules_with_ignore( ignore_list_re, self.linter.config.ignore_paths, ) - modules.sort(key=lambda d: d["name"]) assert modules == expected assert not errors From 4bcbcc4d94799842422d94b11c39944def15c8ef Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Fri, 11 Nov 2022 18:33:38 -0800 Subject: [PATCH 03/15] Update towncrier description for patch. --- doc/whatsnew/fragments/6242.bugfix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/whatsnew/fragments/6242.bugfix b/doc/whatsnew/fragments/6242.bugfix index 4337a0b59c..a7ea7e6f5c 100644 --- a/doc/whatsnew/fragments/6242.bugfix +++ b/doc/whatsnew/fragments/6242.bugfix @@ -1,5 +1,5 @@ -Maintain and reference a set of visited files while expanding the module files +Use dict to track results while expanding the module files from list of module directories, package names, and standalone files to -prevent duplicate scans. +prevent duplicate scans while preserving order. Closes #6242 From 387c240e2882f17f8df24b038706a5934b1d1e83 Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Sat, 12 Nov 2022 06:51:57 -0800 Subject: [PATCH 04/15] Fix deduplication to account for CLI args marker. Add unit test for deduplication. --- pylint/lint/expand_modules.py | 19 ++++++----- tests/lint/unittest_expand_modules.py | 46 ++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py index 2b796e651b..efe4c4c316 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -120,13 +120,16 @@ def expand_modules( is_namespace = modutils.is_namespace(spec) is_directory = modutils.is_directory(spec) if not is_namespace: - result[filepath] = { - "path": filepath, - "name": modname, - "isarg": True, - "basepath": filepath, - "basename": modname, - } + if filepath in result: + result[filepath]["isarg"] = True + else: + result[filepath] = { + "path": filepath, + "name": modname, + "isarg": True, + "basepath": filepath, + "basename": modname, + } has_init = ( not (modname.endswith(".__init__") or modname == "__init__") and os.path.basename(filepath) == "__init__.py" @@ -149,7 +152,7 @@ def expand_modules( result[subfilepath] = { "path": subfilepath, "name": submodname, - "isarg": False, + "isarg": subfilepath in result, "basepath": filepath, "basename": modname, } diff --git a/tests/lint/unittest_expand_modules.py b/tests/lint/unittest_expand_modules.py index a40df405d9..30d3a0306c 100644 --- a/tests/lint/unittest_expand_modules.py +++ b/tests/lint/unittest_expand_modules.py @@ -45,6 +45,14 @@ def test__is_in_ignore_list_re_match() -> None: "path": EXPAND_MODULES, } +this_file_from_init_deduplicated = { + "basename": "lint", + "basepath": INIT_PATH, + "isarg": True, + "name": "lint.unittest_expand_modules", + "path": EXPAND_MODULES, +} + unittest_lint = { "basename": "lint", "basepath": INIT_PATH, @@ -123,7 +131,43 @@ class Checker(BaseChecker): def test_expand_modules( self, files_or_modules: list[str], expected: dict[str, ModuleDescriptionDict] ) -> None: - """Test expand_modules with the default value of ignore-paths.""" + """Test expand_modules with deduplication and the default value of ignore-paths.""" + ignore_list: list[str] = [] + ignore_list_re: list[re.Pattern[str]] = [] + modules, errors = expand_modules( + files_or_modules, + ignore_list, + ignore_list_re, + self.linter.config.ignore_paths, + ) + assert modules == expected + assert not errors + + @pytest.mark.parametrize( + "files_or_modules,expected", + [ + ([__file__, __file__], {this_file["path"]: this_file}), + ( + [EXPAND_MODULES, str(Path(__file__).parent), EXPAND_MODULES], + { + module["path"]: module # pylint: disable=unsubscriptable-object + for module in ( + init_of_package, + test_caching, + test_pylinter, + test_utils, + this_file_from_init_deduplicated, + unittest_lint, + ) + }, + ), + ], + ) + @set_config(ignore_paths="") + def test_expand_modules_deduplication( + self, files_or_modules: list[str], expected: dict[str, ModuleDescriptionDict] + ) -> None: + """Test expand_modules deduplication.""" ignore_list: list[str] = [] ignore_list_re: list[re.Pattern[str]] = [] modules, errors = expand_modules( From 5a6d70b3aa3c7a1704601800e2554eac34dd2b9e Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Sat, 12 Nov 2022 07:22:22 -0800 Subject: [PATCH 05/15] Fix corner case with CLI arg flag handling during deduplication. Also, document how the handling works. --- pylint/lint/expand_modules.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py index efe4c4c316..4b62633830 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -121,6 +121,7 @@ def expand_modules( is_directory = modutils.is_directory(spec) if not is_namespace: if filepath in result: + # Set arg flag if module is also implicitly specified. result[filepath]["isarg"] = True else: result[filepath] = { @@ -152,7 +153,8 @@ def expand_modules( result[subfilepath] = { "path": subfilepath, "name": submodname, - "isarg": subfilepath in result, + # Preserve arg flag if module is also explicitly specified. + "isarg": result.get(subfilepath, {}).get("isarg", False), # type: ignore[call-overload] "basepath": filepath, "basename": modname, } From e2e326dc601fd85ebbc825a35b0ae323caece74f Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Sat, 12 Nov 2022 16:12:50 -0800 Subject: [PATCH 06/15] Factor out package module list for 'expand_modules' unit tests. --- doc/whatsnew/fragments/6242.bugfix | 7 +++--- tests/lint/unittest_expand_modules.py | 35 +++++++++++++-------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/doc/whatsnew/fragments/6242.bugfix b/doc/whatsnew/fragments/6242.bugfix index a7ea7e6f5c..25d323e7e7 100644 --- a/doc/whatsnew/fragments/6242.bugfix +++ b/doc/whatsnew/fragments/6242.bugfix @@ -1,5 +1,4 @@ -Use dict to track results while expanding the module files -from list of module directories, package names, and standalone files to -prevent duplicate scans while preserving order. +Pylint will now filter duplicates given to it before linting. The output should +be the same whether a file is given/discovered multiple times or not. -Closes #6242 +Closes #6242, #4053 diff --git a/tests/lint/unittest_expand_modules.py b/tests/lint/unittest_expand_modules.py index 30d3a0306c..88f058b1ec 100644 --- a/tests/lint/unittest_expand_modules.py +++ b/tests/lint/unittest_expand_modules.py @@ -85,7 +85,6 @@ def test__is_in_ignore_list_re_match() -> None: "path": str(TEST_DIRECTORY / "lint/test_caching.py"), } - init_of_package = { "basename": "lint", "basepath": INIT_PATH, @@ -95,6 +94,20 @@ def test__is_in_ignore_list_re_match() -> None: } +def _list_expected_package_modules( + deduplicating: bool = False, +) -> tuple[dict[str, object], ...]: + """Generates reusable list of modules for our package.""" + return ( + init_of_package, + test_caching, + test_pylinter, + test_utils, + this_file_from_init_deduplicated if deduplicating else this_file_from_init, + unittest_lint, + ) + + class TestExpandModules(CheckerTestCase): """Test the expand_modules function while allowing options to be set.""" @@ -115,14 +128,7 @@ class Checker(BaseChecker): [str(Path(__file__).parent)], { module["path"]: module # pylint: disable=unsubscriptable-object - for module in ( - init_of_package, - test_caching, - test_pylinter, - test_utils, - this_file_from_init, - unittest_lint, - ) + for module in _list_expected_package_modules() }, ), ], @@ -131,7 +137,7 @@ class Checker(BaseChecker): def test_expand_modules( self, files_or_modules: list[str], expected: dict[str, ModuleDescriptionDict] ) -> None: - """Test expand_modules with deduplication and the default value of ignore-paths.""" + """Test expand_modules with the default value of ignore-paths.""" ignore_list: list[str] = [] ignore_list_re: list[re.Pattern[str]] = [] modules, errors = expand_modules( @@ -151,14 +157,7 @@ def test_expand_modules( [EXPAND_MODULES, str(Path(__file__).parent), EXPAND_MODULES], { module["path"]: module # pylint: disable=unsubscriptable-object - for module in ( - init_of_package, - test_caching, - test_pylinter, - test_utils, - this_file_from_init_deduplicated, - unittest_lint, - ) + for module in _list_expected_package_modules(deduplicating=True) }, ), ], From 08b9e1dbc9521ca8bac4d6d5421a40c721a91d50 Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Sat, 12 Nov 2022 16:58:53 -0800 Subject: [PATCH 07/15] Add 'deduplication' to custom Pyenchant dict. --- .pyenchant_pylint_custom_dict.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.pyenchant_pylint_custom_dict.txt b/.pyenchant_pylint_custom_dict.txt index 2b8e846a5b..29f42e3320 100644 --- a/.pyenchant_pylint_custom_dict.txt +++ b/.pyenchant_pylint_custom_dict.txt @@ -74,6 +74,7 @@ cyclomatic dataclass datetime debian +deduplication deepcopy defaultdicts defframe From c59248b709cf44094cd1fcecfb0913aacd308a4d Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Tue, 15 Nov 2022 00:42:48 -0800 Subject: [PATCH 08/15] Appease Mypy. Improve accuracy of comment. --- pylint/lint/expand_modules.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py index 4b62633830..e43208deaf 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -121,7 +121,7 @@ def expand_modules( is_directory = modutils.is_directory(spec) if not is_namespace: if filepath in result: - # Set arg flag if module is also implicitly specified. + # Always set arg flag if module explicitly given. result[filepath]["isarg"] = True else: result[filepath] = { @@ -150,11 +150,12 @@ def expand_modules( subfilepath, is_namespace, path=additional_search_path ) submodname = ".".join(modpath) + # Preserve arg flag if module is also explicitly given. + isarg = subfilepath in result and result[subfilepath]["isarg"] result[subfilepath] = { "path": subfilepath, "name": submodname, - # Preserve arg flag if module is also explicitly specified. - "isarg": result.get(subfilepath, {}).get("isarg", False), # type: ignore[call-overload] + "isarg": isarg, "basepath": filepath, "basename": modname, } From 3d147e3009e5100c2a0091449f306c25c801b818 Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Wed, 16 Nov 2022 17:38:42 -0800 Subject: [PATCH 09/15] Integration Test: Pylint argument deduplication with highly constrained number of branches. --- tests/test_pylint_runners.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index 936de8fd66..7bbf5e7df4 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -5,8 +5,10 @@ from __future__ import annotations +import contextlib import os import pathlib +import shlex import sys from collections.abc import Sequence from io import BufferedReader @@ -57,6 +59,25 @@ def test_runner_with_arguments(runner: _RunCallable, tmpdir: LocalPath) -> None: assert err.value.code == 0 +def test_pylint_argument_deduplication(tmpdir: LocalPath) -> None: + """Check that the Pylint runner does not overreport on duplicate arguments.""" + filepath = os.path.abspath(__file__) + # Ensure that we have 3 branches in this file. + if filepath: + testargs = shlex.split("--report n --score n --max-branches 3") + if testargs: + testargs.extend([filepath] * 4) + if not testargs: + return + exit_stack = contextlib.ExitStack() + exit_stack.enter_context(tmpdir.as_cwd()) + exit_stack.enter_context(patch.object(sys, "argv", testargs)) + err = exit_stack.enter_context(pytest.raises(SystemExit)) + with exit_stack: + run_pylint(testargs) + assert err.value.code == 0 + + def test_pylint_run_jobs_equal_zero_dont_crash_with_cpu_fraction( tmpdir: LocalPath, ) -> None: From dffd61da188a208f845c0c158e4122f0f36475fc Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Wed, 16 Nov 2022 17:56:32 -0800 Subject: [PATCH 10/15] Appease Pyenchant. --- tests/test_pylint_runners.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index 7bbf5e7df4..3bb2780aec 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -60,7 +60,9 @@ def test_runner_with_arguments(runner: _RunCallable, tmpdir: LocalPath) -> None: def test_pylint_argument_deduplication(tmpdir: LocalPath) -> None: - """Check that the Pylint runner does not overreport on duplicate arguments.""" + """Check that the Pylint runner does not over-report on duplicate + arguments. + """ filepath = os.path.abspath(__file__) # Ensure that we have 3 branches in this file. if filepath: From e45a731dd4c46bab67d498fda4dde77ad904d63a Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Thu, 17 Nov 2022 17:15:02 -0800 Subject: [PATCH 11/15] Use 'too-many-branches' functional test file as target for deduplication integration test. --- tests/test_pylint_runners.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index 3bb2780aec..f8518b6471 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -62,15 +62,16 @@ def test_runner_with_arguments(runner: _RunCallable, tmpdir: LocalPath) -> None: def test_pylint_argument_deduplication(tmpdir: LocalPath) -> None: """Check that the Pylint runner does not over-report on duplicate arguments. + + (Github #6242, #4053). """ - filepath = os.path.abspath(__file__) - # Ensure that we have 3 branches in this file. - if filepath: - testargs = shlex.split("--report n --score n --max-branches 3") - if testargs: - testargs.extend([filepath] * 4) - if not testargs: - return + filepath = str( + pathlib.Path(__file__) + .resolve() + .parent.joinpath("functional", "t", "too", "too_many_branches.py") + ) + testargs = shlex.split("--report n --score n --max-branches 13") + testargs.extend([filepath] * 4) exit_stack = contextlib.ExitStack() exit_stack.enter_context(tmpdir.as_cwd()) exit_stack.enter_context(patch.object(sys, "argv", testargs)) From 82948a09fed6a8f1319f225ae76f3818be5e92a4 Mon Sep 17 00:00:00 2001 From: Eric McDonald Date: Thu, 17 Nov 2022 17:32:30 -0800 Subject: [PATCH 12/15] Appease Pyenchant. Again. --- tests/test_pylint_runners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index f8518b6471..7551a868d9 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -63,7 +63,7 @@ def test_pylint_argument_deduplication(tmpdir: LocalPath) -> None: """Check that the Pylint runner does not over-report on duplicate arguments. - (Github #6242, #4053). + (GitHub #6242, #4053). """ filepath = str( pathlib.Path(__file__) From 7a8fe9819e63a968c395e8a5858f0ba180d7667b Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Fri, 18 Nov 2022 09:26:13 +0100 Subject: [PATCH 13/15] Update tests/test_pylint_runners.py --- tests/test_pylint_runners.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index 7551a868d9..fa9f830812 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -59,17 +59,14 @@ def test_runner_with_arguments(runner: _RunCallable, tmpdir: LocalPath) -> None: assert err.value.code == 0 -def test_pylint_argument_deduplication(tmpdir: LocalPath) -> None: +def test_pylint_argument_deduplication(tmpdir: LocalPath, tests_directory: Path) -> None: """Check that the Pylint runner does not over-report on duplicate arguments. - (GitHub #6242, #4053). + See https://github.com/PyCQA/pylint/issues/6242 and + https://github.com/PyCQA/pylint/issues/4053 """ - filepath = str( - pathlib.Path(__file__) - .resolve() - .parent.joinpath("functional", "t", "too", "too_many_branches.py") - ) + filepath = str(tests_directory / "functional/t/too/too_many_branches.py") testargs = shlex.split("--report n --score n --max-branches 13") testargs.extend([filepath] * 4) exit_stack = contextlib.ExitStack() From ae0585693635913f5a0b57cb89a0a8d3fe8de853 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Nov 2022 08:27:20 +0000 Subject: [PATCH 14/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_pylint_runners.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index fa9f830812..c8da2d6c18 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -59,7 +59,9 @@ def test_runner_with_arguments(runner: _RunCallable, tmpdir: LocalPath) -> None: assert err.value.code == 0 -def test_pylint_argument_deduplication(tmpdir: LocalPath, tests_directory: Path) -> None: +def test_pylint_argument_deduplication( + tmpdir: LocalPath, tests_directory: Path +) -> None: """Check that the Pylint runner does not over-report on duplicate arguments. From c67f204bd2c24fe81efff0d44a33cb7d7b39a89a Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Fri, 18 Nov 2022 10:37:55 +0100 Subject: [PATCH 15/15] Update tests/test_pylint_runners.py --- tests/test_pylint_runners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index c8da2d6c18..8e68f8eaa1 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -60,7 +60,7 @@ def test_runner_with_arguments(runner: _RunCallable, tmpdir: LocalPath) -> None: def test_pylint_argument_deduplication( - tmpdir: LocalPath, tests_directory: Path + tmpdir: LocalPath, tests_directory: pathlib.Path ) -> None: """Check that the Pylint runner does not over-report on duplicate arguments.