我一直在学习如何在 tox 中为我的 python 项目进行测试。
我有(应该是)一个相当标准的 tox 初始化文件,如下所示:
[tox]
envlist=py27,flake8
...
[testenv:flake8]
deps=flake8
commands=flake8 library # 'library' is temp. name of project
一切看起来都很正常,所有测试都有效,甚至 flake8 输出也通过了(下面的输出)。但是,tox 引发了一个 InvocationError(它对使用 pylint 进行的测试也是如此)
flake8 recreate: /Users/shostakovich/projects/project_templates/library/.tox/flake8
flake8 installdeps: flake8
flake8 inst: /Users/shostakovich/projects/project_templates/library/.tox/dist/library-0.1.0.zip
flake8 installed: flake8==2.4.1,library==0.1.0,mccabe==0.3,pep8==1.5.7,pyflakes==0.8.1,wheel==0.24.0
library/__main__.py:12:1: F401 'os' imported but unused
library/__main__.py:13:1: F401 're' imported but unused
...
ERROR: InvocationError: '/Users/shostakovich/projects/project_templates/library/.tox/flake8/bin/flake8 library'
我在 MaxOSX 10.9.5 上运行 tox 2.0.2。如果我直接调用 flake8 或 pylint(flake8 的版本如上所示),问题就会消失。
最佳答案
tox
没有失败,它有效!
您的 flake8
源代码检查有发现,因此 tox
失败退出,这就是您的测试结果。修复发现的问题,大功告成!
您可以在 tox.ini
中配置 flake8
运行以忽略特定代码。来自flake8 docs :
[flake8]
ignore = E226,E302,E41
还有更多您可能感兴趣的选项,例如select = ...
用于启用白名单的代码检查。
关于python - flake8/pylint 在 Tox 测试环境中失败,引发 InvocationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30692685/