Get coverage as percentage

Issue #503 closed
controversial created an issue

I'm using the command-line API to measure coverage as part of my testing script. I'd like, however, to be able to get the coverage over all files as a single number from my Coverage object.

I spent a while poking through some objects and the source. I found the coverage.results.Numbers class, but after measuring my coverage with the Python API, I can't find a way to get an instance of this class.

Comments (8)

  1. space one

    I am also interested in this. I want to do something like: cov.stop() assert cov.get_percentage() == 100

  2. Ned Batchelder repo owner

    Mulling over how to implement this, it seems like this will be the only result you want? That is, you won't be writing an HTML report and then also using get_percentage(), since cov.html_report() already returns the total coverage number.

  3. space one

    Nice would be some "Result" object (so that it could be adapted in the future). which has the percentage as a property. The percentage is 100% even if there are branches which were only executed one way? So maybe another property like uncovered_branches (int) would also be nice!

  4. Ned Batchelder repo owner

    @spaceone .start and .stop happen during the measurement phase. Computing the percentage is the reporting phase, which involves analyzing code, a slow operation. We'll need to continue to keep them separate.

  5. Log in to comment