Pylint:禁用特定文件夹的特定警告 [英] Pylint: Disable specific warnings for specific folder
问题描述
我们有一个这样布局的 Python 项目:
We have a Python project laid out like this:
project/
├── .pylintrc
├── module1.py
├── module2.py
└── tests/
├── test_module1.py
└── test_module2.py
我们的单元和功能测试位于名为 tests/
的文件夹中.在测试时,pylint 警告 missing-docstring
、invalid-name
和 protected-access
不相关.另一方面,这些警告对于项目中的实际代码非常有用.
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.
我的问题是是否可以在 missing-docstring
、invalid-name
和 protected-access
中添加忽略>.pylintrc-文件,适用于 tests/
-文件夹中的模块 only?
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?
如果可能,我们不希望为这些警告添加 #
-disables 到文件夹内的每个测试模块.
If possible, we do not want to add #
-disables for these warnings to every test-module inside the folder.
推荐答案
据我所知,您无法对整个目录或文件禁用特定警告.
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.
这篇关于Pylint:禁用特定文件夹的特定警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!