从 Pylint 中排除测试文件

Exclude test files from Pylint

我的单元测试与源代码并存。即

├── __init__.py
├── formatter.py
└── test_formatter.py

有没有办法让 Pylint 从其分析中排除所有前缀为 test_ 的文件? ignore 配置选项似乎不喜欢通配符。

确实没有通配符支持。您可以在 https://github.com/PyCQA/pylint

上提交功能请求或更好的拉取请求

这是通过 --ignore-patterns 选项在 Pylint 1.6 中作为一项功能引入的。

所以,要忽略上面的文件:

pylint myproject --ignore-patterns=test_.*?py

将以下内容添加到 pylintrc 中的 [master] 部分对我有用。它会忽略 foo_test.pytest_far.py.

ignore-patterns=(.)*_test\.py,test_(.)*\.py