Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to sort the text report #199

Closed
nedbat opened this issue Sep 28, 2012 · 9 comments · Fixed by #1005
Closed

Add a way to sort the text report #199

nedbat opened this issue Sep 28, 2012 · 9 comments · Fixed by #1005
Labels
enhancement New feature or request report

Comments

@nedbat
Copy link
Owner

nedbat commented Sep 28, 2012

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!

Rob

From: Ned Batchelder [mailto:ned@nedbatchelder.com]
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.

--Ned.

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

Netherlands

@nedbat
Copy link
Owner Author

nedbat commented Oct 1, 2012

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

 

Optional

(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,

Rob

@nedbat
Copy link
Owner Author

nedbat commented Apr 20, 2014

Original comment by bachmann1234 (Bitbucket: bachmann1234, GitHub: bachmann1234)


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.

@nedbat
Copy link
Owner Author

nedbat commented Nov 23, 2014

FYI, changeset b7762d1a6614 (bb) introduced the report --skip-covered option, which leaves out any file with 100% coverage.

@nedbat
Copy link
Owner Author

nedbat commented Jun 10, 2016

Control over the sorting column is available in the report:sort option in the .coveragerc. This work is completed in f4001cd0cd52 (bb). 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.

@nedbat
Copy link
Owner Author

nedbat commented Dec 7, 2017

Original comment by Max Nordlund (Bitbucket: maxnordlund, GitHub: maxnordlund)


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.

@nedbat nedbat closed this as completed Dec 7, 2017
@nedbat nedbat added major enhancement New feature or request report labels Jun 23, 2018
@jerinpetergeorge
Copy link
Contributor

jerinpetergeorge commented Jun 29, 2020

I have made a couple of changes to source code and it seems working (I haven't done broad tests 😉 )

source-code reference

        # Sort the lines and write them out.
        if getattr(self.config, 'sort', None):
            field = self.config.sort.lower()
            if field[0] == '-':
                field = field[1:]
                reverse = True
            else:
                reverse = False
            position = column_order.get(field)
            if position is None:
                raise CoverageException("Invalid sorting option: {0!r}".format(self.config.sort))
            lines.sort(key=lambda l: (l[1][position], l[0]), reverse=reverse)

and the .coveragerc config

[report]
sort = -Cover

@jerinpetergeorge
Copy link
Contributor

jerinpetergeorge commented Jun 29, 2020

@nedbat Any update on this feature? Why this issue was closed?

@nedbat
Copy link
Owner Author

nedbat commented Jun 29, 2020

I closed it when I added report:sort. But it seems like there is interest in more control. Would you like to make a pull request? Or I might get to it in the next few weeks.

@jerinpetergeorge
Copy link
Contributor

jerinpetergeorge commented Jun 29, 2020

Yeah, I will try my best to make a PR asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants