pytest-pylint

0.21.0 · active · verified Tue Apr 14

pytest-pylint is a pytest plugin that integrates Pylint, a Python static code analysis tool, into the pytest testing framework. It allows developers to run Pylint checks as part of their test suite, ensuring code quality and adherence to coding standards. The library is actively maintained, with regular updates to support newer versions of pytest, Pylint, and Python. The current version is 0.21.0.

Warnings

Install

Imports

Quickstart

To use pytest-pylint, simply install it. It automatically integrates with pytest. You can then run pytest with the `--pylint` flag to enable Pylint checks. For more control, use `--pylint-rcfile` to specify a Pylint configuration file (e.g., `.pylintrc`) or `--pylint-error-types` to filter which message types cause a test failure (e.g., 'E' for error, 'F' for fatal, 'W' for warning, 'C' for convention, 'R' for refactor).

import pytest

# my_bad_module.py (example of code with a pylint warning)
def calculate(a, b):
    result = a + b # W0612: Unused variable 'result'
    return a + b

# To run pylint with pytest, save the above in 'my_bad_module.py'
# and create a dummy 'test_my_module.py' if needed for pytest discovery:
# touch test_my_module.py

# Then, run from your terminal:
# pytest --pylint my_bad_module.py
# Or to restrict error types:
# pytest --pylint --pylint-error-types=E,F my_bad_module.py

# Example .pylintrc content (optional, in project root):
# [MESSAGES CONTROL]
# disable=W0612

# Example pytest.ini content (optional, in project root):
# [pytest]
# addopts = --pylint --pylint-error-types=E,F

view raw JSON →