我想使用python pep8来检查我的代码并生成关于我的应用程序质量的报告。
我用以下命令手动使用它:
# In my app root directory
pep8 . > report.txt这将生成一个report.txt文件,其中包含由PEP8检测到的所有pep8错误。
但是现在,我需要把它包含在织物脚本中。我刚这么做了
def test_pep8():
env.run("pep8 . > report.txt")当我运行test_pep8时,我有以下错误,我不知道为什么:
(test)➜ fab test_pep8
[localhost] Executing task 'test_pep8'
[localhost] local: pep8 . > report.txt
Fatal error: local() encountered an error (return code 1) while executing 'pep8 . > report'您知道为什么会出现这样的错误吗?:(生成文件报告,但此错误代码正在停止我的fabric命令。
发布于 2014-07-16 15:28:17
这是因为pep8 .返回非零错误代码,这意味着它找到了警告,而代码没有验证。根据织物的Failure handling
Fabric默认为“快速失败”的行为模式:如果有任何问题发生,例如返回非零返回值的远程程序,或者fabfile的Python代码遇到异常,执行将立即停止。
解决方案是将warn_only设置为True,并临时使用 context manager将错误设置为hide
from fabric.context_managers import settings, hide
def test_pep8():
with settings(hide('warnings', 'running', 'stdout', 'stderr'),
warn_only=True):
env.run("pep8 . > report.txt")https://stackoverflow.com/questions/24784459
复制相似问题