Easy check for a certain coverage in tests.

Issue #139 resolved
Jorge Eduardo Cardona created an issue


It would be great if coverage add something like a --target option to check if the code pass a certain percentage of coverage and return with an error code if this doesn't happen, ie: --target 95.


Comments (6)

  1. Ned Batchelder repo owner

    This makes the most sense to me as a new coverage command. "coverage check --target=95" would behave as you suggest. Or perhaps "coverage check" could simply return the total coverage percentage as its status value, and then the shell script could do what it wants with it?

  2. Jorge Eduardo Cardona reporter


    A new command is great, and if it's possible a cov.check(95) that returns True or False would be great too, I'm currently trying to add a --target to nosecover3 plugin in order to fail the testsuite if the code doesn't pass some target (or goal) of test coverage, and this method would be perfect.

    Best Regards.

  3. Malcolm Purvis

    I have a similar need to Jorge. I'm writing a test script that needs to fail if tests fail or coverage falls. I'd like API access to the total coverage but at the moment I'm forced to parse the report text to extract it.

  4. Igor Sobreira

    Nice! I liked the way it was done, minimal change to the internal, just option to the report commands.

    When using the API directly, I ended up doing this:

    cov = coverage.coverage(..)
    ret = run_all_my_tests()
    if ret == 0:
        covered = cov.report()
        assert covered > 100, "Not enough coverage"

    I wonder if fail_under couldn't be an option to report() or coverage()... but I liked this api, it's flexible and the information you need is right there.

  5. Log in to comment