This package has moved to https://github.com/pylint-dev/pylint-pytest. Active development occurs on that fork.
A Pylint plugin to suppress pytest-related false positives.
Requirements:
pylint
pytest>=4.6
To install:
$ pip install pylint-pytest
Enable via command line option --load-plugins
$ pylint --load-plugins pylint_pytest <path_to_your_sources>
Or in pylintrc
:
[MASTER]
load-plugins=pylint_pytest
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
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):
...
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)
...
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 when using deprecated @pytest.yield_fixture
decorator (ref)
import pytest
@pytest.yield_fixture # <- Using a deprecated @pytest.yield_fixture decorator
def yield_fixture():
yield
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():
...
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():
...
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
See CHANGELOG.
pylint-pytest
is available under MIT license.