How can I make Python's coverage tool fail if any unit tests fail?

Viewed 2219

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.

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

  1. If one or more tests failed, the 'coverage run' command would fail, which would communicate to my shell script that something went wrong.
  2. Or if the coverage was insufficient, the 'coverage run' command would fail (using --fail-under).

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

1 Answers

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.

Related