Get coverage as percentage

Issue #503 new
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 (7)

  1. 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.

  2. 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!

  3. Ned Batchelder repo owner

    @space one .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.

  4. Log in to comment