Skip to content

Commit 48212e2

Browse files
authored
Merge pull request #27 from anis-campos/support-pylint-3
See more details in #27
2 parents fc8fa90 + a9a022f commit 48212e2

File tree

10 files changed

+45
-39
lines changed

10 files changed

+45
-39
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## [Unreleased]
44

5+
## [1.1.7] - 2023-12-04
6+
7+
This is a small release to support additionally Pylint v3.
8+
It should be noted, however, that for linting, Pylint must be v3 or newer (due to backwards-incompatible changes).
9+
10+
### Fixed
11+
12+
* Support pylint v3 and drop v1 (https://github.com/pylint-dev/pylint-pytest/pull/27)
13+
514
## [1.1.6] - 2023-11-20
615

716
This is a small bugfix release.

pylint_pytest/checkers/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
from pylint.checkers import BaseChecker
22

3+
from pylint_pytest.utils import PYLINT_VERSION_MAJOR
4+
35

46
class BasePytestChecker(BaseChecker):
7+
if PYLINT_VERSION_MAJOR < 3:
8+
# todo(maybe-remove): if we only support pylint>=3
9+
# Since https://github.com/pylint-dev/pylint/pull/8404, pylint does not need this
10+
# __implements__ pattern. keeping it for retro compatibility with pylint==2.x
11+
# pylint: disable=import-outside-toplevel,no-name-in-module
12+
from pylint.interfaces import IAstroidChecker
13+
14+
__implements__ = IAstroidChecker
15+
516
name = "pylint-pytest"

pylint_pytest/checkers/class_attr_loader.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from typing import Optional, Set
22

33
from astroid import Assign, Attribute, ClassDef, Name
4-
from pylint.interfaces import IAstroidChecker
54

65
from ..utils import _can_use_fixture, _is_class_autouse_fixture
76
from . import BasePytestChecker
87

98

109
class ClassAttrLoader(BasePytestChecker):
11-
__implements__ = IAstroidChecker
1210
msgs = {"E6400": ("", "pytest-class-attr-loader", "")}
1311

1412
in_setup = False

pylint_pytest/checkers/fixture.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
from typing import Set, Tuple
66

77
import astroid
8-
import pylint
98
import pytest
109
from pylint.checkers.variables import VariablesChecker
11-
from pylint.interfaces import IAstroidChecker
1210

1311
from ..utils import (
1412
_can_use_fixture,
@@ -42,7 +40,6 @@ def pytest_collectreport(self, report):
4240

4341

4442
class FixtureChecker(BasePytestChecker):
45-
__implements__ = IAstroidChecker
4643
msgs = {
4744
"W6401": (
4845
"Using a deprecated @pytest.yield_fixture decorator",
@@ -235,7 +232,7 @@ def visit_functiondef(self, node):
235232
for arg in node.args.args:
236233
self._invoked_with_func_args.add(arg.name)
237234

238-
# pylint: disable=bad-staticmethod-argument,too-many-branches # The function itself is an if-return logic.
235+
# pylint: disable=bad-staticmethod-argument # The function itself is an if-return logic.
239236
@staticmethod
240237
def patch_add_message(
241238
self, msgid, line=None, node=None, args=None, confidence=None, col_offset=None
@@ -314,10 +311,4 @@ def patch_add_message(
314311
):
315312
return
316313

317-
if int(pylint.__version__.split(".")[0]) >= 2:
318-
FixtureChecker._original_add_message(
319-
self, msgid, line, node, args, confidence, col_offset
320-
)
321-
else:
322-
# python2 + pylint1.9 backward compatibility
323-
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence)
314+
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)

pylint_pytest/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import inspect
22

33
import astroid
4+
import pylint
5+
6+
PYLINT_VERSION_MAJOR = int(pylint.__version__.split(".")[0])
47

58

69
def _is_pytest_mark_usefixtures(decorator):

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,11 @@ load-plugins= [
123123
"pylint.extensions.broad_try_clause",
124124
"pylint.extensions.check_elif",
125125
"pylint.extensions.code_style",
126-
"pylint.extensions.comparetozero",
127126
"pylint.extensions.comparison_placement",
128127
"pylint.extensions.confusing_elif",
129128
# "pylint.extensions.consider_ternary_expression", # Not a pretty refactoring
130129
"pylint.extensions.docparams",
131130
"pylint.extensions.docstyle",
132-
"pylint.extensions.emptystring",
133131
"pylint.extensions.eq_without_hash",
134132
"pylint.extensions.for_any_all",
135133
"pylint.extensions.mccabe",
@@ -174,4 +172,8 @@ output-format = "colorized"
174172
ignored-argument-names = "_.*"
175173

176174
[tool.pylint."messages control"]
177-
enable = ["useless-suppression"]
175+
enable = [
176+
"useless-suppression",
177+
"use-implicit-booleaness-not-comparison-to-zero",
178+
"use-implicit-booleaness-not-comparison-to-string",
179+
]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
long_description_content_type="text/markdown",
2929
packages=find_packages(exclude=["tests*", "sandbox"]),
3030
install_requires=[
31-
"pylint<3",
31+
"pylint>=2",
3232
"pytest>=4.6",
3333
],
3434
python_requires=">=3.6",

tests/base_tester.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@
33
from abc import ABC
44
from pathlib import Path
55
from pprint import pprint
6-
from typing import Any, Dict, List
6+
from typing import List, Type
77

88
import astroid
9-
from pylint.testutils import MessageTest, UnittestLinter
10-
11-
try:
12-
from pylint.utils import ASTWalker
13-
except ImportError:
14-
# for pylint 1.9
15-
from pylint.utils import PyLintASTWalker as ASTWalker
16-
179
from pylint.checkers import BaseChecker
10+
from pylint.testutils import MessageTest, UnittestLinter
11+
from pylint.utils import ASTWalker
1812

1913
import pylint_pytest.checkers.fixture
2014

@@ -29,10 +23,9 @@ def get_test_root_path() -> Path:
2923

3024
class BasePytestTester(ABC):
3125
CHECKER_CLASS = BaseChecker
32-
IMPACTED_CHECKER_CLASSES: List[BaseChecker] = []
26+
IMPACTED_CHECKER_CLASSES: List[Type[BaseChecker]] = []
3327
MSG_ID: str
3428
msgs: List[MessageTest] = []
35-
CONFIG: Dict[str, Any] = {}
3629

3730
def __init_subclass__(cls, **kwargs):
3831
super().__init_subclass__(**kwargs)
@@ -78,14 +71,10 @@ def setup_method(self):
7871
self.checker = self.CHECKER_CLASS(self.linter)
7972
self.impacted_checkers = []
8073

81-
for key, value in self.CONFIG.items():
82-
setattr(self.checker.config, key, value)
8374
self.checker.open()
8475

8576
for checker_class in self.IMPACTED_CHECKER_CLASSES:
8677
checker = checker_class(self.linter)
87-
for key, value in self.CONFIG.items():
88-
setattr(checker.config, key, value)
8978
checker.open()
9079
self.impacted_checkers.append(checker)
9180

tests/test_regression.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pylint
21
import pytest
32
from base_tester import BasePytestTester
43
from pylint.checkers.variables import VariablesChecker
@@ -18,9 +17,5 @@ def test_import_twice(self, enable_plugin):
1817
"""catch a coding error when using fixture + if + inline import"""
1918
self.run_linter(enable_plugin)
2019

21-
if int(pylint.__version__.split(".")[0]) < 2:
22-
# for some reason pylint 1.9.5 does not raise unused-import for inline import
23-
self.verify_messages(1, msg_id="unused-import")
24-
else:
25-
self.verify_messages(2, msg_id="unused-import")
20+
self.verify_messages(2, msg_id="unused-import")
2621
self.verify_messages(1, msg_id="redefined-outer-name")

tox.ini

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
[tox]
2-
envlist = py36,py37,py38,py39,py310,py311
2+
envlist =
3+
py36-pylint2
4+
py37-pylint2
5+
py38-pylint{2,3}
6+
py39-pylint{2,3}
7+
py310-pylint{2,3}
8+
py311-pylint{2,3}
39
skipsdist = True
410
passenv =
511
FORCE_COLOR
@@ -8,6 +14,8 @@ passenv =
814
deps =
915
pytest
1016
pytest-cov
17+
pylint2: pylint>2,<3
18+
pylint3: pylint>3,<4
1119
commands =
1220
pip install --upgrade --editable .
1321
pytest --cov --cov-append {env:PYTEST_CI_ARGS:} {tty:--color=yes} {posargs:tests}

0 commit comments

Comments
 (0)