如果任何单元测试失败,如何使 Python 的覆盖工具失败? [英] How can I make Python's coverage tool fail if any unit tests fail?

查看:49
本文介绍了如果任何单元测试失败,如何使 Python 的覆盖工具失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 shell 脚本来确保我的单元测试通过并且我的代码有足够的测试覆盖率.我只想运行我的测试代码一次.

I want to use a shell script to make sure that my unit tests pass and that my code has sufficient test coverage. I only want to run my test code once.

我希望我可以通过 coverage 工具运行我的测试,并且从单次运行开始:

I was hoping that I could run my tests via the coverage tool and that from that single run:

  1. 如果一个或多个测试失败,coverage run"命令就会失败,这会通知我的 shell 脚本出了问题.
  2. 或者,如果覆盖率不足,coverage run"命令将失败(使用 --fail-under).

如果不重定向命令输出并搜索关键字(例如失败),您将如何做到这一点?

How would you do that without redirecting command output and searching for key words (e.g. fail)?

推荐答案

coverage run 会以你正在运行的程序的退出状态退出.如果您以这种方式运行测试运行器,那么退出状态应该透明地传递.

coverage run will exit with the exit status of the program you are running. If you run your test runner that way, then the exit status should be passed through transparently.

这篇关于如果任何单元测试失败,如何使 Python 的覆盖工具失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆