Pylint: Disable specific warnings for specific folder

2024/11/18 20:01:29

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.

Answer

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.

https://en.xdnf.cn/q/26526.html

Related Q&A

PyCharm: Configuring multi-hop remote Interpreters via SSH

To connect to the computer at my office I need to run ssh twice. First to connect to the host-1 and then from host-1 to host-2 and each one has different credentials. However the configuration menu in …

Return results from multiple models with Django REST Framework

I have three models — articles, authors and tweets. Im ultimately needing to use Django REST Framework to construct a feed that aggregates all the objects using the Article and Tweet models into one r…

Comparing XML in a unit test in Python

I have an object that can build itself from an XML string, and write itself out to an XML string. Id like to write a unit test to test round tripping through XML, but Im having trouble comparing the tw…

Passing a tuple as command line argument

My requirement is to pass a tuple as command line argument like --data (1,2,3,4)I tried to use the argparse module, but if I pass like this it is receiving as the string (1,2,3,4). I tried by giving ty…

Setting exit code in Python when an exception is raised

$ cat e.py raise Exception $ python e.py Traceback (most recent call last):File "e.py", line 1, in <module>raise Exception Exception $ echo $? 1I would like to change this exit code fr…

cmake error the source does not appear to contain CMakeLists.txt

Im installing opencv in ubuntu 16.04. After installing the necessary prerequisites I used the following command:-kvs@Hunter:~/opencv_contrib$ mkdir build kvs@Hunter:~/opencv_contrib$ cd build kvs@Hunte…

Overlay an image segmentation with numpy and matplotlib

I am trying to overlay two images. The first one is a 512x512 NumPy array (from a CT image). The second one is also a 512x512 NumPy array but I am just interested in the pixels where the value is large…

Why isnt my variable set when I call the other function? [duplicate]

This question already has answers here:How do I get ("return") a result (output) from a function? How can I use the result later?(4 answers)How can I fix a TypeError that says an operator (…

Return max of zero or value for a pandas DataFrame column

I want to replace negative values in a pandas DataFrame column with zero.Is there a more concise way to construct this expression?df[value][df[value] < 0] = 0

Getting str object has no attribute get in Django

views.pydef generate_xml(request, number):caller_id = x-x-x-xresp = twilio.twiml.Response()with resp.dial(callerId=caller_id) as r:if number and re.search([\d\(\)\- \+]+$, number):r.number(number)else:…