Skip to content

Commit

Permalink
Merge branch 'master' into drop-eol-python-add-3.12
Browse files Browse the repository at this point in the history
# By Stavros Ntentos (4) and Anis Da Silva Campos (2)
# Via GitHub (1) and Stavros Ntentos (1)
* master:
  `.github/workflows/run-tests.yaml`: `codecov/codecov-action@v3`: Adjust `fail_ci_if_error`
  Implement `slsa-framework`?
  Update/Prepare Changelog for v1.1.7
  use pylint v3 in the repo
  remove support of pylint v1
  Support pylint v3

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
#	tox.ini

Additionally, some minor format modifications at `CHANGELOG.md`
  • Loading branch information
stdedos committed Dec 3, 2023
2 parents 65fa52b + 48212e2 commit f1e6197
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 40 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@

### Removed

- Support for Python 3.6 & 3.7 (#23)
* Support for Python 3.6 & 3.7 (https://github.com/pylint-dev/pylint-pytest/pull/23)

## [1.1.7] - 2023-12-04

This is a small release to support additionally Pylint v3.
It should be noted, however, that for linting, Pylint must be v3 or newer (due to backwards-incompatible changes).

### Fixed

* Support pylint v3 and drop v1 (https://github.com/pylint-dev/pylint-pytest/pull/27)

## [1.1.6] - 2023-11-20

Expand Down
11 changes: 11 additions & 0 deletions pylint_pytest/checkers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from pylint.checkers import BaseChecker

from pylint_pytest.utils import PYLINT_VERSION_MAJOR


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

__implements__ = IAstroidChecker

name = "pylint-pytest"
2 changes: 0 additions & 2 deletions pylint_pytest/checkers/class_attr_loader.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from typing import Optional, Set

from astroid import Assign, Attribute, ClassDef, Name
from pylint.interfaces import IAstroidChecker

from ..utils import _can_use_fixture, _is_class_autouse_fixture
from . import BasePytestChecker


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

in_setup = False
Expand Down
13 changes: 2 additions & 11 deletions pylint_pytest/checkers/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
from typing import Set, Tuple

import astroid
import pylint
import pytest
from pylint.checkers.variables import VariablesChecker
from pylint.interfaces import IAstroidChecker

from ..utils import (
_can_use_fixture,
Expand Down Expand Up @@ -42,7 +40,6 @@ def pytest_collectreport(self, report):


class FixtureChecker(BasePytestChecker):
__implements__ = IAstroidChecker
msgs = {
"W6401": (
"Using a deprecated @pytest.yield_fixture decorator",
Expand Down Expand Up @@ -235,7 +232,7 @@ def visit_functiondef(self, node):
for arg in node.args.args:
self._invoked_with_func_args.add(arg.name)

# pylint: disable=bad-staticmethod-argument,too-many-branches # The function itself is an if-return logic.
# pylint: disable=bad-staticmethod-argument # The function itself is an if-return logic.
@staticmethod
def patch_add_message(
self, msgid, line=None, node=None, args=None, confidence=None, col_offset=None
Expand Down Expand Up @@ -314,10 +311,4 @@ def patch_add_message(
):
return

if int(pylint.__version__.split(".")[0]) >= 2:
FixtureChecker._original_add_message(
self, msgid, line, node, args, confidence, col_offset
)
else:
# python2 + pylint1.9 backward compatibility
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence)
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
3 changes: 3 additions & 0 deletions pylint_pytest/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import inspect

import astroid
import pylint

PYLINT_VERSION_MAJOR = int(pylint.__version__.split(".")[0])


def _is_pytest_mark_usefixtures(decorator):
Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ load-plugins= [
"pylint.extensions.broad_try_clause",
"pylint.extensions.check_elif",
"pylint.extensions.code_style",
"pylint.extensions.comparetozero",
"pylint.extensions.comparison_placement",
"pylint.extensions.confusing_elif",
# "pylint.extensions.consider_ternary_expression", # Not a pretty refactoring
"pylint.extensions.docparams",
"pylint.extensions.docstyle",
"pylint.extensions.emptystring",
"pylint.extensions.eq_without_hash",
"pylint.extensions.for_any_all",
"pylint.extensions.mccabe",
Expand Down Expand Up @@ -175,4 +173,8 @@ output-format = "colorized"
ignored-argument-names = "_.*"

[tool.pylint."messages control"]
enable = ["useless-suppression"]
enable = [
"useless-suppression",
"use-implicit-booleaness-not-comparison-to-zero",
"use-implicit-booleaness-not-comparison-to-string",
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
long_description_content_type="text/markdown",
packages=find_packages(exclude=["tests*", "sandbox"]),
install_requires=[
"pylint<3",
"pylint>=2",
"pytest>=4.6",
],
python_requires=">=3.8",
Expand Down
19 changes: 4 additions & 15 deletions tests/base_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
from abc import ABC
from pathlib import Path
from pprint import pprint
from typing import Any, Dict, List
from typing import List, Type

import astroid
from pylint.testutils import MessageTest, UnittestLinter

try:
from pylint.utils import ASTWalker
except ImportError:
# for pylint 1.9
from pylint.utils import PyLintASTWalker as ASTWalker

from pylint.checkers import BaseChecker
from pylint.testutils import MessageTest, UnittestLinter
from pylint.utils import ASTWalker

import pylint_pytest.checkers.fixture

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

class BasePytestTester(ABC):
CHECKER_CLASS = BaseChecker
IMPACTED_CHECKER_CLASSES: List[BaseChecker] = []
IMPACTED_CHECKER_CLASSES: List[Type[BaseChecker]] = []
MSG_ID: str
msgs: List[MessageTest] = []
CONFIG: Dict[str, Any] = {}

def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
Expand Down Expand Up @@ -78,14 +71,10 @@ def setup_method(self):
self.checker = self.CHECKER_CLASS(self.linter)
self.impacted_checkers = []

for key, value in self.CONFIG.items():
setattr(self.checker.config, key, value)
self.checker.open()

for checker_class in self.IMPACTED_CHECKER_CLASSES:
checker = checker_class(self.linter)
for key, value in self.CONFIG.items():
setattr(checker.config, key, value)
checker.open()
self.impacted_checkers.append(checker)

Expand Down
7 changes: 1 addition & 6 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pylint
import pytest
from base_tester import BasePytestTester
from pylint.checkers.variables import VariablesChecker
Expand All @@ -18,9 +17,5 @@ def test_import_twice(self, enable_plugin):
"""catch a coding error when using fixture + if + inline import"""
self.run_linter(enable_plugin)

if int(pylint.__version__.split(".")[0]) < 2:
# for some reason pylint 1.9.5 does not raise unused-import for inline import
self.verify_messages(1, msg_id="unused-import")
else:
self.verify_messages(2, msg_id="unused-import")
self.verify_messages(2, msg_id="unused-import")
self.verify_messages(1, msg_id="redefined-outer-name")
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[tox]
envlist = py38,py39,py310,py311
envlist =
py38-pylint{2,3}
py39-pylint{2,3}
py310-pylint{2,3}
py311-pylint{2,3}
skipsdist = True
passenv =
FORCE_COLOR
Expand All @@ -8,6 +12,8 @@ passenv =
deps =
pytest
pytest-cov
pylint2: pylint>2,<3
pylint3: pylint>3,<4
commands =
pip install --upgrade --editable .
pytest --cov --cov-append {env:PYTEST_CI_ARGS:} {tty:--color=yes} {posargs:tests}

0 comments on commit f1e6197

Please sign in to comment.