Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pylint-dev/pylint-pytest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.4
Choose a base ref
...
head repository: pylint-dev/pylint-pytest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.1.5
Choose a head ref
  • 14 commits
  • 9 files changed
  • 3 contributors

Commits on Nov 2, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    bb0b523 View commit details

Commits on Oct 23, 2023

  1. Make nsp/nate/better-unused-argument merge-able with origin/master

    Signed-off-by: Stavros Ntentos <[email protected]>
    stdedos committed Oct 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    360461c View commit details
  2. Merge remote-tracking branch 'origin/master' into replay/fix/nate/bet…

    …ter-unused-argument
    
    # By Stavros Ntentos (15) and others
    # Via GitHub (9) and Stavros Ntentos (1)
    * origin/master:
      Release v1.1.3
      Fixing _is_pytest_fixture
      test direct import
      Improve packaging + Release v1.1.3rc1
      Release v1.1.3rc0 (#17)
      Fix testing + coverage
      Improvements for `.github/workflows/run-tests.yaml`
      Fix the repository badges
      Roll back `from __future__ import annotations` for Python 3.6
      Fix mypy issues
      Activate mypy in pre-commit
      [mypy] Fix Item "None" of "Optional[Module]" has no attribute "__file__"
      Carry over some `.pylintrc` configuration
      Minor re-ordering of the `tool.pylint`, with some comments
      Move the pylint configuration to pyproject.toml
      [pylint] Add pylint in the continuous integration and pre-commit
      Activate ruff, ignore the typing of classvar
      Upgrade the changelog for 1.1.3a0 release (#10)
      Use ruff instead of flake8 pyupgrade autoflake and isort
      Enable https://github.com/asottile/pyupgrade + `.git-blame-ignore-revs`
      `pre-commit run -a`
      Add `.pre-commit-config.yaml`
      Add a release job to publish on pypi on github tag creation
      MOAR Improvements: Cross-OS testing, `.gitignore` updates, supporting only `pylint<3`, coverage at Codecov, drop other CI
      CI: Modernize, MOAR Pythons, GH-Actions
    
    Signed-off-by: Stavros Ntentos <[email protected]>
    
    # Conflicts:
    #	pylint_pytest/checkers/fixture.py
    stdedos committed Oct 23, 2023
    Copy the full SHA
    c249eb7 View commit details

Commits on Nov 6, 2023

  1. Extend coverage for `if node.name in FixtureChecker._pytest_fixtures[…

    …fixname][0].argnames:`
    
    Signed-off-by: Stavros Ntentos <[email protected]>
    stdedos committed Nov 6, 2023
    Copy the full SHA
    8756cc4 View commit details
  2. Copy the full SHA
    bb6af8d View commit details
  3. Merge pull request #21 from stdedos/replay/fix/nate/better-unused-arg…

    …ument
    
    See more details in #21
    stdedos authored Nov 6, 2023
    Copy the full SHA
    c1547d9 View commit details

Commits on Nov 11, 2023

  1. Copy the full SHA
    d11811e View commit details
  2. Move --cov-report=html to addopts

    Non-`--cov` invocation is unaffected;
    "no reason" not to generate `--cov-report=html` in an untracked directory AFAIS.
    
    Signed-off-by: Stavros Ntentos <[email protected]>
    stdedos committed Nov 11, 2023
    Copy the full SHA
    90e4141 View commit details
  3. Fix tests running via PyCharm

    Would've been better to get the path via `requests.config.rootdir`,
    but it looks like a pain to inject the `requests` fixture here.
    
    Signed-off-by: Stavros Ntentos <[email protected]>
    stdedos committed Nov 11, 2023
    Copy the full SHA
    8edad60 View commit details
  4. Improve copy-paste docstring from 8756cc4

    Signed-off-by: Stavros Ntentos <[email protected]>
    stdedos committed Nov 11, 2023
    Copy the full SHA
    d8db8e4 View commit details
  5. Copy the full SHA
    e29fe48 View commit details
  6. Copy the full SHA
    a4245b1 View commit details
  7. Merge pull request #25 from stdedos/ci/fix-windows-artifacts-slugific…

    …ation
    
    See more details in #25
    stdedos authored Nov 11, 2023
    Copy the full SHA
    3cee43d View commit details

Commits on Nov 13, 2023

  1. Release v1.1.5

    * removes more false positives for unused-argument (#21)
    * A collection of minor improvements to tests (#26)
    * Windows Artifacts have incorrect Slugification (#25)
    
    Signed-off-by: Stavros Ntentos <[email protected]>
    stdedos committed Nov 13, 2023
    Copy the full SHA
    c84ad36 View commit details
11 changes: 9 additions & 2 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -42,7 +42,14 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Slugify GITHUB_REPOSITORY
- name: Slugify GITHUB_REPOSITORY (win)
if: ${{ matrix.os == 'windows-latest' }}
run: |
$slug = $env:GITHUB_REPOSITORY -replace '/', '_'
echo "GITHUB_REPOSITORY_SLUG=$slug" | tee -Append $env:GITHUB_ENV
- name: Slugify GITHUB_REPOSITORY (non-win)
if: ${{ matrix.os != 'windows-latest' }}
run: echo "GITHUB_REPOSITORY_SLUG=${GITHUB_REPOSITORY////_}" >> $GITHUB_ENV

- name: Set up Python ${{ matrix.python-version }}
@@ -60,7 +67,7 @@ jobs:
- name: Test with tox
env:
FORCE_COLOR: 1
PYTEST_CI_ARGS: --cov-report=xml --cov-report=html --junitxml=test_artifacts/test_report.xml --color=yes
PYTEST_CI_ARGS: --cov-report=xml --junitxml=test_artifacts/test_report.xml --color=yes
run: tox ${{ matrix.python-version == '3.6' && '--skip-missing-interpreters=true' || '' }}

- name: Upload coverage reports to Codecov
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,13 +2,23 @@

## [Unreleased]

## [1.1.5] - 2023-11-13

This is a small bugfix release.

### Fixed

* removes more false positives for unused-argument (https://github.com/pylint-dev/pylint-pytest/pull/21)
* A collection of minor improvements to tests (https://github.com/pylint-dev/pylint-pytest/pull/26)
* Windows Artifacts have incorrect Slugification (https://github.com/pylint-dev/pylint-pytest/pull/25)

## [1.1.4] - 2023-11-06

This is a small bugfix release.

### Fixed

* `anis-campos/fix_is_pytest_fixture`: (https://github.com/pylint-dev/pylint-pytest/pull/2)
* `anis-campos/fix_is_pytest_fixture` (https://github.com/pylint-dev/pylint-pytest/pull/2)
Astroid has different semantics when using `import pytest` or `from pytest import ...`,
which affects the detection of pytest fixtures.

17 changes: 13 additions & 4 deletions pylint_pytest/checkers/fixture.py
Original file line number Diff line number Diff line change
@@ -116,10 +116,10 @@ def visit_module(self, node):
is_test_module = True
break

stdout, stderr = sys.stdout, sys.stderr
try:
with open(os.devnull, "w") as devnull:
# suppress any future output from pytest
stdout, stderr = sys.stdout, sys.stderr
sys.stderr = sys.stdout = devnull

# run pytest session with customized plugin to collect fixtures
@@ -210,7 +210,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
# pylint: disable=bad-staticmethod-argument,too-many-branches # 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
@@ -267,9 +267,18 @@ def patch_add_message(
msgid == "unused-argument"
and _can_use_fixture(node.parent.parent)
and isinstance(node.parent, astroid.Arguments)
and node.name in FixtureChecker._pytest_fixtures
):
return
if node.name in FixtureChecker._pytest_fixtures:
# argument is used as a fixture
return

fixnames = (
arg.name for arg in node.parent.args if arg.name in FixtureChecker._pytest_fixtures
)
for fixname in fixnames:
if node.name in FixtureChecker._pytest_fixtures[fixname][0].argnames:
# argument is used by a fixture
return

# check W0621 redefined-outer-name
if (
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ module = [
check_untyped_defs = true

[tool.pytest.ini_options]
addopts = "--verbose --cov-config=pyproject.toml"
addopts = "--verbose --cov-config=pyproject.toml --cov-report=html"

[tool.ruff]
# ruff is less lenient than pylint and does not make any exceptions
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

setup(
name="pylint-pytest",
version="1.1.4",
version="1.1.5",
author="Stavros Ntentos",
author_email="133706+stdedos@users.noreply.github.com",
license="MIT",
11 changes: 10 additions & 1 deletion tests/base_tester.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
from abc import ABC
from pathlib import Path
from pprint import pprint
from typing import Any, Dict, List

@@ -21,6 +22,11 @@
pylint_pytest.checkers.fixture.FILE_NAME_PATTERNS = ("*",)


def get_test_root_path() -> Path:
"""Assumes ``base_tester.py`` is at ``<root>/tests``."""
return Path(__file__).parent


class BasePytestTester(ABC):
CHECKER_CLASS = BaseChecker
IMPACTED_CHECKER_CLASSES: List[BaseChecker] = []
@@ -41,7 +47,10 @@ def run_linter(self, enable_plugin):
# pylint: disable-next=protected-access
target_test_file = sys._getframe(1).f_code.co_name.replace("test_", "", 1)
file_path = os.path.join(
os.getcwd(), "tests", "input", self.MSG_ID, target_test_file + ".py"
get_test_root_path(),
"input",
self.MSG_ID,
target_test_file + ".py",
)

with open(file_path) as fin:
7 changes: 6 additions & 1 deletion tests/base_tester_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import pytest
from base_tester import BasePytestTester
from base_tester import BasePytestTester, get_test_root_path

# pylint: disable=unused-variable


def test_get_test_root_path():
assert get_test_root_path().name == "tests"
assert (get_test_root_path() / "input").is_dir()


def test_init_subclass_valid_msg_id():
some_string = "some_string"

34 changes: 34 additions & 0 deletions tests/input/unused-argument/func_param_as_fixture_arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
This module illustrates a situation in which unused-argument should be
suppressed, but is not.
"""

import pytest


@pytest.fixture
def myfix(arg):
"""A fixture that requests a function param"""
print("arg is ", arg)
return True


@pytest.mark.parametrize("arg", [1, 2, 3])
def test_myfix(myfix, arg):
"""A test function that uses the param through a fixture"""
assert myfix


@pytest.mark.parametrize("narg", [4, 5, 6])
def test_nyfix(narg): # unused-argument
"""A test function that does not use its param"""
assert True


@pytest.mark.parametrize("arg", [1, 2, 3])
def test_narg_is_used_nowhere(myfix, narg):
"""
A test function that does not use its param (``narg``):
Not itself, nor through a fixture (``myfix``).
"""
assert myfix
5 changes: 5 additions & 0 deletions tests/test_unused_argument.py
Original file line number Diff line number Diff line change
@@ -29,3 +29,8 @@ def test_caller_not_a_test_func(self, enable_plugin):
def test_args_and_kwargs(self, enable_plugin):
self.run_linter(enable_plugin)
self.verify_messages(2)

@pytest.mark.parametrize("enable_plugin", [True, False])
def test_func_param_as_fixture_arg(self, enable_plugin):
self.run_linter(enable_plugin)
self.verify_messages(2 if enable_plugin else 3)