我有一个典型的 Python 代码库,其中数十个目录中包含数百个
.py
文件,以及数十个充满 /tests/
文件的 test_whatever.py
目录(我使用 pytest
运行)。
但是,老实说,我对测试文件中的事情的关心程度比真实代码中的事情要低得多。对于
pylint
文件夹中的文件,如何忽略这四件事?
/tests/
missing-module-docstring
missing-class-docstring
missing-function-docstring
protected-access
中:
pylintrc
您可以使用 tox,它是一个通用的 virtualenv 管理和测试命令行工具。 毒可以帮助你:
在每个环境中运行测试
在根级别添加 tox.ini 文件。请参阅下图中的项目结构
在 tox.ini 中,运行测试和 pylint 的基本配置如下所示:
pip install tox
如您所见,我将 pylint 拆分为 2 个命令,这让我可以控制如何以不同的方式对
src和tests
进行 lint 处理。
要运行 tox(测试 + lint),只需在终端中从 tox.ini 目录运行 [tox]
minversion = 2.0
envlist = py36, pylint
skipsdist = True
[testenv]
commands = {envbindir}/pytest {posargs}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/dev-requirements.txt
recreate = False
passenv = *
[testenv:pylint]
basepython=python3.6
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/dev-requirements.txt
commands=pylint src
pylint --disable=missing-module-docstring,missing-class-docstring tests
。
如果您只想运行 pylint 那么您可以运行
tox
将 pylint 拆分为 prodcode 目录和测试目录有什么问题吗?
deps = -r {toxinidir}/requirements.txt 命令= python -m pylint --rcfile=pylintrc --fail-under=9.5 --ignore-paths=prodcode/tests prodcode python -m pylint --rcfile=pylintrc --fail-under=9.5 --disable=missing-function-docstring,missing-class-docstring,unused-argument,missing-module-docstring prodcode/tests
它效果很好,但我无法用这种方法找到另一种解决方案,所以我有点不确定?唯一的缺点是测试时间稍微增加了几秒。
我错过了什么吗?