From e6215ac2f3c939e33a5a384f571d1c87f6f14dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Tue, 16 Aug 2022 11:51:08 +0200 Subject: [PATCH] Use ``pylint-pytest-plugin`` --- pylint/testutils/lint_module_test.py | 2 +- pylintrc | 1 + requirements_test_min.txt | 1 + tests/checkers/unittest_unicode/unittest_bad_chars.py | 2 -- tests/config/test_functional_config_loading.py | 1 - tests/conftest.py | 2 -- tests/lint/test_caching.py | 3 --- tests/lint/unittest_lint.py | 6 ++---- tests/message/conftest.py | 2 -- tests/primer/test_primer_external.py | 2 +- tests/primer/test_primer_stdlib.py | 2 +- tests/pyreverse/test_diadefs.py | 2 -- tests/pyreverse/test_inspector.py | 2 -- tests/reporters/unittest_reporting.py | 2 -- tests/test_epylint.py | 2 +- tests/test_functional.py | 2 +- tests/test_import_graph.py | 2 -- tests/test_regr.py | 2 -- tests/test_self.py | 2 +- tests/testutils/test_lint_module_output_update.py | 2 -- tests/testutils/test_output_line.py | 2 -- 21 files changed, 10 insertions(+), 34 deletions(-) diff --git a/pylint/testutils/lint_module_test.py b/pylint/testutils/lint_module_test.py index 0d3dbb0bf4..01a03fa9e3 100644 --- a/pylint/testutils/lint_module_test.py +++ b/pylint/testutils/lint_module_test.py @@ -246,7 +246,7 @@ def _get_actual(self) -> tuple[MessageCounter, list[OutputLine]]: return received_msgs, received_output_lines def _runTest(self) -> None: - __tracebackhide__ = True # pylint: disable=unused-variable + __tracebackhide__ = True modules_to_check = [self._test_file.source] self._linter.check(modules_to_check) expected_messages, expected_output = self._get_expected() diff --git a/pylintrc b/pylintrc index 3323052d41..f46f6d6c16 100644 --- a/pylintrc +++ b/pylintrc @@ -32,6 +32,7 @@ load-plugins= pylint.extensions.typing, pylint.extensions.redefined_variable_type, pylint.extensions.comparison_placement, + pylint_pytest_plugin, # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the # number of processors available to use. diff --git a/requirements_test_min.txt b/requirements_test_min.txt index 8202b4d775..5572a5e85d 100644 --- a/requirements_test_min.txt +++ b/requirements_test_min.txt @@ -2,6 +2,7 @@ # astroid dependency is also defined in pyproject.toml astroid==2.12.2 # Pinned to a specific version for tests typing-extensions~=4.3 +pylint-pytest-plugin==0.1.0a2 pytest~=7.1 pytest-benchmark~=3.4 pytest-timeout~=2.1 diff --git a/tests/checkers/unittest_unicode/unittest_bad_chars.py b/tests/checkers/unittest_unicode/unittest_bad_chars.py index 41445e2262..308198043f 100644 --- a/tests/checkers/unittest_unicode/unittest_bad_chars.py +++ b/tests/checkers/unittest_unicode/unittest_bad_chars.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# pylint: disable=redefined-outer-name - from __future__ import annotations import itertools diff --git a/tests/config/test_functional_config_loading.py b/tests/config/test_functional_config_loading.py index 64227df792..3684e45dc4 100644 --- a/tests/config/test_functional_config_loading.py +++ b/tests/config/test_functional_config_loading.py @@ -17,7 +17,6 @@ and ``"functional_remove":``. Check the existing code for examples. """ -# pylint: disable=redefined-outer-name import logging import warnings from pathlib import Path diff --git a/tests/conftest.py b/tests/conftest.py index 1ebe62e976..0d7b624516 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# pylint: disable=redefined-outer-name - from __future__ import annotations import os diff --git a/tests/lint/test_caching.py b/tests/lint/test_caching.py index fe6ccc234a..40eb0f740d 100644 --- a/tests/lint/test_caching.py +++ b/tests/lint/test_caching.py @@ -2,9 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# Pytest fixtures work like this by design -# pylint: disable=redefined-outer-name - import sys from pathlib import Path diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 2f3a5c1701..ff11b751c7 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# pylint: disable=redefined-outer-name - from __future__ import annotations import argparse @@ -418,8 +416,8 @@ def test_errors_only(initialized_linter: PyLinter) -> None: linter = initialized_linter linter._error_mode = True linter._parse_error_mode() - checkers = linter.prepare_checkers() - checker_names = {c.name for c in checkers} + prepared_checkers = linter.prepare_checkers() + checker_names = {c.name for c in prepared_checkers} should_not = {"design", "format", "metrics", "miscellaneous", "similarities"} assert set() == should_not & checker_names diff --git a/tests/message/conftest.py b/tests/message/conftest.py index e410578350..9a3659593c 100644 --- a/tests/message/conftest.py +++ b/tests/message/conftest.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# pylint: disable=redefined-outer-name - from __future__ import annotations from collections.abc import ValuesView diff --git a/tests/primer/test_primer_external.py b/tests/primer/test_primer_external.py index 01b1367b1d..dc56dfce7e 100644 --- a/tests/primer/test_primer_external.py +++ b/tests/primer/test_primer_external.py @@ -44,7 +44,7 @@ def test_primer_external_packages_no_crash_batch_one( package: PackageToLint, caplog: LogCaptureFixture, ) -> None: - __tracebackhide__ = True # pylint: disable=unused-variable + __tracebackhide__ = True TestPrimer._primer_test(package, caplog) @staticmethod diff --git a/tests/primer/test_primer_stdlib.py b/tests/primer/test_primer_stdlib.py index 6cae6fd367..d0076a1483 100644 --- a/tests/primer/test_primer_stdlib.py +++ b/tests/primer/test_primer_stdlib.py @@ -48,7 +48,7 @@ def test_primer_stdlib_no_crash( test_module_location: str, test_module_name: str, capsys: CaptureFixture ) -> None: """Test that pylint does not produce any crashes or fatal errors on stdlib modules.""" - __tracebackhide__ = True # pylint: disable=unused-variable + __tracebackhide__ = True os.chdir(test_module_location) with _patch_stdout(io.StringIO()): try: diff --git a/tests/pyreverse/test_diadefs.py b/tests/pyreverse/test_diadefs.py index 35dcd0e3a2..77d2b14729 100644 --- a/tests/pyreverse/test_diadefs.py +++ b/tests/pyreverse/test_diadefs.py @@ -4,8 +4,6 @@ """Unit test for the extensions.diadefslib modules.""" -# pylint: disable=redefined-outer-name - from __future__ import annotations import sys diff --git a/tests/pyreverse/test_inspector.py b/tests/pyreverse/test_inspector.py index 15f9d305a7..97910bb729 100644 --- a/tests/pyreverse/test_inspector.py +++ b/tests/pyreverse/test_inspector.py @@ -4,8 +4,6 @@ """For the visitors.diadefs module.""" -# pylint: disable=redefined-outer-name - from __future__ import annotations import os diff --git a/tests/reporters/unittest_reporting.py b/tests/reporters/unittest_reporting.py index ebc4a225f4..41e1795d6e 100644 --- a/tests/reporters/unittest_reporting.py +++ b/tests/reporters/unittest_reporting.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# pylint: disable=redefined-outer-name - from __future__ import annotations import sys diff --git a/tests/test_epylint.py b/tests/test_epylint.py index e1b090395a..4ffe0e3e38 100644 --- a/tests/test_epylint.py +++ b/tests/test_epylint.py @@ -3,7 +3,7 @@ # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt """Test for issue https://github.com/PyCQA/pylint/issues/4286.""" -# pylint: disable=redefined-outer-name + from pathlib import PosixPath import pytest diff --git a/tests/test_functional.py b/tests/test_functional.py index 74b541bcf7..bbfcde4bd6 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -42,7 +42,7 @@ def test_functional( test_file: FunctionalTestFile, recwarn: WarningsRecorder, pytestconfig: Config ) -> None: - __tracebackhide__ = True # pylint: disable=unused-variable + __tracebackhide__ = True if UPDATE_FILE.exists(): lint_test: ( LintModuleOutputUpdate | testutils.LintModuleTest diff --git a/tests/test_import_graph.py b/tests/test_import_graph.py index a05ebbd711..56f71c8804 100644 --- a/tests/test_import_graph.py +++ b/tests/test_import_graph.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# pylint: disable=redefined-outer-name - from __future__ import annotations import os diff --git a/tests/test_regr.py b/tests/test_regr.py index 80492ae78e..ac5a5662bb 100644 --- a/tests/test_regr.py +++ b/tests/test_regr.py @@ -6,8 +6,6 @@ to be incorporated in the automatic functional test framework """ -# pylint: disable=redefined-outer-name - from __future__ import annotations import os diff --git a/tests/test_self.py b/tests/test_self.py index 53c9fb11bc..0fa73db43e 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -977,7 +977,7 @@ def test_one_module_fatal_error(self) -> None: """Fatal errors in one of several modules linted still exits non-zero.""" valid_path = join(HERE, "conftest.py") invalid_path = join(HERE, "garbagePath.py") - self._runtest([valid_path, invalid_path, "--disable=C"], code=1) + self._runtest([valid_path, invalid_path, "--disable=C"], code=5) @pytest.mark.parametrize( "args, expected", diff --git a/tests/testutils/test_lint_module_output_update.py b/tests/testutils/test_lint_module_output_update.py index 1c9e589af7..4b762feb34 100644 --- a/tests/testutils/test_lint_module_output_update.py +++ b/tests/testutils/test_lint_module_output_update.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# pylint: disable=redefined-outer-name - from __future__ import annotations from collections.abc import Callable diff --git a/tests/testutils/test_output_line.py b/tests/testutils/test_output_line.py index 2a21ce1fd5..6a9642c16f 100644 --- a/tests/testutils/test_output_line.py +++ b/tests/testutils/test_output_line.py @@ -2,8 +2,6 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -# pylint: disable=redefined-outer-name - from __future__ import annotations from collections.abc import Callable