Pylint:禁用子类的警告

时间:2014-09-28 21:24:51

标签: python pylint

我在项目中使用pylint而且有些困扰我。

例如,我创建了一个单元测试(unittest.TestCase的子类)。这个父类有很多方法,所以pylint说“R0904:公共方法太多”。 要“解决”此警告,我禁用localy此检查。

但是我需要编写很多单元测试,每次都禁止localy这个检查。

所以我正在寻找一种方法来禁用unittest.TestCase的所有子类的这个检查。 在pylint配置文件可能是,但我没有找到任何东西。

你有任何想法吗?

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:2)

您可以定义pylintrc文件并使用它运行pylint。你可以这样做:

$ pylint --generate-rcfile > pylintrc

这将生成默认的pylintrc文件。这应该有一个看起来像这样的段落:

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
#disable=

您想在该段落之后添加以下行(但在 MESSAGES CONTROL 部分内):

disable=R0904

或:

disable=too-many-public-methods

然后,您需要使用该rcfile运行pylint。这可以使用--rcfile=<file>参数来完成。