如果测试没有足够的Python覆盖率,如何使travis失败
问题描述:
如果我的测试覆盖范围不足,我可能会导致travis失败,例如<例如90%。
I it possible to have travis fail if my test don't have enough coverage, say < 90% for example.
通常,我使用以下travis配置条目运行测试。
Normally I run my tests with the following travis config entry.
script:
- coverage run --source="mytestmodule" setup.py test
答
根据此链接,如果您将-fail-under
开关添加到覆盖范围报告
命令,如果代码覆盖率低于给定的百分比,它将以非零退出代码退出(travis将视为失败)。
According to this link, if you add the --fail-under
switch to the coverage report
command, it will exit with a non-zero exit code (which travis will see as a failure) if the code coverage is below the given percentage.
这将使 .travis.yml
文件的脚本部分看起来像:
That would make the script section of your .travis.yml
file look like:
script
- coverage run --source="mytestmodule" setup.py test
- coverage report --fail-under=80
当然,您可以用任意百分比替换80。
Of course you could replace 80 with whatever percentage you'd like.