Pylint: Disable specific warnings for specific folder

Viewed 7662

We have a Python project laid out like this:

project/
├── .pylintrc
├── module1.py
├── module2.py
└── tests/
    ├── test_module1.py
    └── test_module2.py

Our unit and function tests reside in the folder called tests/. When it comes to tests the pylint warnings missing-docstring, invalid-name and protected-access are not relevant. On the other hand, these warnings are very useful for the actual code in the project.

My question is whether it is possible to add ignores for missing-docstring, invalid-name and protected-access in the .pylintrc-file that apply to modules in the tests/-folder only?

If possible, we do not want to add #-disables for these warnings to every test-module inside the folder.

2 Answers

Yes, you can create .pylintrc in the tests folder, and another in the project folder.

Add tests to the "ignore" section of the project

[MASTER]
ignore=tests

See: https://docs.pylint.org/en/1.6.0/run.html

Then run separately:

pylint project
pylint project/tests
Related