如果测试没有覆盖 python,如何让 travis 失败

How to get travis to fail if tests do not have enough coverage for python

如果我的测试没有足够的覆盖率,我可能会让 travis 失败,例如 < 90%。

通常我 运行 使用以下 travis 配置条目进行测试。

script:
 - coverage run --source="mytestmodule" setup.py test

根据此 link,如果您将 --fail-under 开关添加到 coverage report 命令,它将以非零退出代码退出(travis 将其视为失败)如果代码覆盖率低于给定百分比。

这将使您的 .travis.yml 文件的脚本部分看起来像:

script
 - coverage run --source="mytestmodule" setup.py test
 - coverage report --fail-under=80

当然,您可以将 80 替换为您想要的任何百分比。