Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylint: Disable specific warnings for specific folder

Tags:

python

pylint

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.

like image 329
imolit Avatar asked Mar 23 '16 15:03

imolit


People also ask

How do I disable Pylint warnings?

This may be done by adding # pylint: disable=some-message,another-one at the desired block level or at the end of the desired line of code.

How do I ignore a folder in Pylint?

You can not give a path, but only the "basename" of the directory. E.g., use --ignore=lib instead of --ignore-=appengine-toolkit/gaetk/lib . The problem is you will ignore all directories named lib .

How do you make a Pylint ignore an error?

you can ignore it by adding a comment in the format # pylint: disable=[problem-code] at the end of the line where [problem-code] is the value inside pylint(...) in the pylint message – for example, abstract-class-instantiated for the problem report listed above.

How do I know if a Pylint is ignoring a file?

The solution was to include --disable=file-ignored in the Pylint command options.


2 Answers

As far as I'm aware you can't disable specific warnings for entire directories or files.

However, you can disable all warnings for specific directories using the following on the command line:

--ignore=<file[,file]>

The file here can be a directory.

Personally, and I know you said you'd rather not, I'd add a disable to the top of each file.

like image 59
Luke D. Smith Avatar answered Oct 06 '22 22:10

Luke D. Smith


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
like image 38
Erik Aronesty Avatar answered Oct 06 '22 22:10

Erik Aronesty