Add a way to sort the text report

Issue #199 resolved
Ned Batchelder repo owner created an issue

Hi Ned,

The HTML output looks very good, however I’m running the coverage tool on a VMware and just want to mail the output as plain text to my colleagues.

Sending all those HTML files to all of them (or copy them to a server) is too much, so I need another trick - maybe just a python filter that sorts it out.

Thanks for your time!


From: Ned Batchelder [] Sent: Friday, September 28, 2012 14:56 To: Tillaart, Rob van den Subject: Re: question about coverage tool

Hi Rob,

In the HTML report, you can click on the column headers to sort by the column you're interested in.


On 9/28/2012 7:33 AM, Tillaart, Rob van den wrote:

Hi Ned,

Just new to python development I found the coverage tool which does a good job for Q&A.

Q: is there an option to sort the output on coverage %?

If not I would like to put it on the “wishlist” for next release.

A sorted list makes it easier to see which files needs attention most,

Thanks in advance,

Rob Tillaart


Comments (5)

  1. Ned Batchelder reporter
    Thanks Ned for creating the ticket,
    I made a list of my requirements, made them as generic as possible
    (1) enable sorting on coverage %column  (default seems to be name)
       =>  ideally on any column  [name, statements, miss, coverage]
    (2) ascending sorting (default)
    (3) descending sorting
    (4) remove the lines with 100% coverage from the overview -> show only tests that need attention, useful for big projects to minimize output
    (5) show only topN  lines, eg top 10 or top 20  -> minimizes output
    (6) Total  #files  versus  #files@100%  -> indicator of the fragmentation of the coverage
    Calls could look like:
    Coverage report  --sort=coverage --descending  --no100% ...
    Coverage report  --sort=statements --…
    Coverage report  --sort=miss --no100% ...
    Coverage report  --sort=name --descending   ... 
    Coverage report  --sort=coverage --no100%  --top=15 ...
    Think no short version needed (like –s) as the word sort is already short
    (you might add above to the ticket)
    Thanks again,
  2. Matt Bachmann

    I took a look into this ticket. The currently implementation does not store coverage numbers. They are computed by the fly.

    It seems expensive to compute and store all this to sort on other properties and this could be better achieved though command line tools or other post processing.

  3. Ned Batchelder reporter

    Control over the sorting column is available in the report:sort option in the .coveragerc. This work is completed in f4001cd0cd52. It doesn't provide the option to sort descending, or to control it from the command line. We'll see if there is interest in adding that support.

  4. Max Nordlund

    Fast forward a year later, and at least I would like to see that feature. I tend to run my tests in a small split, and getting the files with the lowest coverage last makes it easy to see what I need to work on.

    I propose -cover/+cover (or just cover) to specify direction.

  5. Log in to comment