Skip to main content

A Pylint plugin to suppress pytest-related false positives.

Project description

pylint-pytest

PyPI - Version PyPI - Python Version PyPI - Downloads PyPI - License

Github - Testing codecov

Code style: black Checked with mypy Pylint Ruff

Say Thanks!

A Pylint plugin to suppress pytest-related false positives.

Installation

Requirements:

  • pylint
  • pytest>=4.6

To install:

$ pip install pylint-pytest

Usage

Enable via command line option --load-plugins

$ pylint --load-plugins pylint_pytest <path_to_your_sources>

Or in .pylintrc:

[MASTER]
load-plugins=pylint_pytest

Suppressed Pylint Warnings

unused-argument

FP when a fixture is used in an applicable function but not referenced in the function body, e.g.

def test_something(conftest_fixture):  # <- Unused argument 'conftest_fixture'
    assert True

unused-import

FP when an imported fixture is used in an applicable function, e.g.

from fixture_collections import (
    imported_fixture,
)  # <- Unused imported_fixture imported from fixture_collections


def test_something(imported_fixture):
    ...

redefined-outer-name

FP when an imported/declared fixture is used in an applicable function, e.g.

from fixture_collections import imported_fixture


def test_something(
    imported_fixture,
):  # <- Redefining name 'imported_fixture' from outer scope (line 1)
    ...

no-member

FP when class attributes are defined in setup fixtures

import pytest


class TestClass(object):
    @staticmethod
    @pytest.fixture(scope="class", autouse=True)
    def setup_class(request):
        cls = request.cls
        cls.defined_in_setup_class = True

    def test_foo(self):
        assert (
            self.defined_in_setup_class
        )  # <- Instance of 'TestClass' has no 'defined_in_setup_class' member

Raise new warning(s)

W6401 deprecated-pytest-yield-fixture

Raise when using deprecated @pytest.yield_fixture decorator (ref)

import pytest


@pytest.yield_fixture  # <- Using a deprecated @pytest.yield_fixture decorator
def yield_fixture():
    yield

W6402 useless-pytest-mark-decorator

Raise when using every @pytest.mark.* for the fixture (ref)

import pytest


@pytest.fixture
def awesome_fixture():
    ...


@pytest.fixture
@pytest.mark.usefixtures(
    "awesome_fixture"
)  # <- Using useless `@pytest.mark.*` decorator for fixtures
def another_awesome_fixture():
    ...

W6403 deprecated-positional-argument-for-pytest-fixture

Raise when using deprecated positional arguments for fixture decorator (ref)

import pytest


@pytest.fixture("module")  # <- Using a deprecated positional arguments for fixture
def awesome_fixture():
    ...

F6401 cannot-enumerate-pytest-fixtures

Raise when the plugin cannot enumerate and collect pytest fixtures for analysis

NOTE: this warning is only added to test modules (test_*.py / *_test.py)

import no_such_package  # <- pylint-pytest plugin cannot enumerate and collect pytest fixtures

Changelog

See CHANGELOG.

License

pylint-pytest is available under MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylint_pytest-1.1.8.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

pylint_pytest-1.1.8-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file pylint_pytest-1.1.8.tar.gz.

File metadata

  • Download URL: pylint_pytest-1.1.8.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for pylint_pytest-1.1.8.tar.gz
Algorithm Hash digest
SHA256 5c862c88870aa8eb1b376df48ab9e820b5bdadfe37d965aa9ac567a6305955ca
MD5 dd5be60ebcd27a7628b0b330314a32c1
BLAKE2b-256 13b25d39125fedd30bfa50f755bdb30f1d5ee2ebde5f54ca7f7bc4cc4e9d51ef

See more details on using hashes here.

File details

Details for the file pylint_pytest-1.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for pylint_pytest-1.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8a532c1709c161406b8459bfc414c57a32a4ab488efd4bc97a22a21cb235331f
MD5 1591dd4b66302326af8fd4267fcb0dab
BLAKE2b-256 fb34e5ef1ee982cc211d5feda95032a7f48d96542cd8985eb722f539e7b9e877

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page