我有一个典型的Python代码库,其中包含了几十个目录中的数百个.py
文件,还有几十个/tests/
目录中填充了test_whatever.py
文件(我使用pytest
运行)。
但是,老实说,与实际代码相比,我在测试文件中关心pylint
的标准要低得多。对于/tests/
文件夹中的文件,我如何忽略这四件事?
missing-module-docstring
missing-class-docstring
missing-function-docstring
protected-access
我唯一成功解决的问题就是函数docstring 1,方法是将它放入我的pylintrc
中
no-docstring-rgx=^_|^test_
其他的有可能修好吗?(我不能将测试文件完全排除在linting之外。)
发布于 2021-08-22 14:14:07
您可以使用tox,它是一个通用的虚拟环境管理和测试命令行工具。毒理对你有帮助:
你可以在他们的官方网站上读到更多关于毒理的信息。
用pip install tox
安装毒物
在根级别添加tox.ini文件。见下图中的项目结构
在tox.ini中,运行测试和pylint的基本配置如下所示:
[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拆分为2个命令,这些命令允许我控制如何链接我的src并进行不同的测试。
要运行tox (test+ lint),只需从tox
目录在终端上运行tox.ini。
如果您只想运行pylint,那么可以运行tox -e pylint
。
https://stackoverflow.com/questions/68855524
复制相似问题