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

Infrastructure improvement: Add Coverage reporting #46

Open
wilfredinni opened this issue Apr 25, 2019 · 10 comments
Open

Infrastructure improvement: Add Coverage reporting #46

wilfredinni opened this issue Apr 25, 2019 · 10 comments

Comments

@wilfredinni
Copy link
Contributor

Meaby is a good idea to add test coverage to the project. I did it in a fork and right now there is just a 42% covered.

Captura de Pantalla 2019-04-24 a la(s) 20 05 13

@cool-RR
Copy link
Owner

cool-RR commented Apr 25, 2019

Great work. @bittner How can we add this to our CI setup? (And hopefully with the HTML report that the coverage module generates.)

(I'd want to exclude third_party and include the tests package.)

@cool-RR cool-RR changed the title Coverage/Codecov Add Coverage reporting Apr 25, 2019
@cool-RR
Copy link
Owner

cool-RR commented Apr 25, 2019

Ah shit, looks like the coverage results are misleading, and fixing them wouldn't be trivial. This is because the coverage module uses sys.settrace to install a trace function, as does PySnooper. Therefore any lines that are run under PySnooper's tracer are excluded from the coverage report.

Perhaps it's possible to get our tracer to also run the coverage tracer?

@nedbat Is there a way to make it work?

@nedbat
Copy link

nedbat commented Apr 25, 2019

In theory it isn't hard: when you set your trace function, first use sys.gettrace to get the current trace function. In your function, call that one. There will still be gaps: the lines literally in your trace function will not be traced. I have the same problem trying to coverage-measure coverage.py.

@cool-RR
Copy link
Owner

cool-RR commented Apr 25, 2019

@nedbat I tried that, and indeed had the problem of lines in my trace functions not getting traced. Of course, that's where all my critical lines are that I want to have coverage for.

I'm thinking about writing a PEP for this. I know this has been a long-time problem for people who write development tools, and I've asked my friends at Wingware how they're dealing with it. Imagine trying to develop a very complex debugger, without using a debugger!

I'm thinking that perhaps Python needs unlimited levels of tracers. Which means that instead of setting one tracer in settrace, there will be a list of tracers that you append to. Then, if I run PySnooper under coverage, we'll have two tracers. Once the PySnooper tracer kicks into action, only the coverage tracer keeps tracing.

If this works, then people could debug debuggers, measure coverage on debuggers, debug coverage tools, measure coverage on coverage tools, etc.

What do you think about that?

@nedbat
Copy link

nedbat commented Apr 25, 2019

I don't know what monsters await in trying to implement something like that. A different approach that I have considered is to unit-test my tracing code by calling it myself. That is, I have an idea how my trace() function should behave. I should be able to write tests that emulate Python calling it, and see if it does what I want.

The difficulty there is accurately emulating Python, especially in your case where you are examining data in the stack. One possibility there is to add another layer of complexity: a new trace function (trace_capture) would record the events and the state of the world it sees, then those events would be replayed to my trace function later, and I can coverage-measure that second execution. Again, there are lots of ways this could go wrong, so I have never experimented with it, and it's more complicated for your project than it is for mine.

Proposing that Python change, and then waiting for it to get implemented, seems like a very long path to what you need.

Perhaps the simplest thing you can do to increase the coverage measurement of PySnooper is to refactor your code so that as much of it as possible can be tested outside of the trace function.

@cool-RR
Copy link
Owner

cool-RR commented Apr 25, 2019

Thanks Ned!

@bittner
Copy link
Collaborator

bittner commented Apr 25, 2019

Great work. @bittner How can we add this to our CI setup? (And hopefully with the HTML report that the coverage module generates.)

Simply

  • add a [testenv:coverage] section to tox.ini with the appropriate commands,
  • add coverage to the envlist in the [tox] section and
  • include it in the list of jobs in .travis.yml.

Without a dependency on an external service (e.g. Coveralls) this will be a bit less nice to consume, but still sufficiently useful.

@cool-RR
Copy link
Owner

cool-RR commented Apr 25, 2019

Thanks. I think that until we can get a sensible result for coverage (i.e. inside the tracer), there isn't much point in doing that. If anyone's interested in working on it, go ahead.

@cool-RR cool-RR changed the title Add Coverage reporting Infrastructure improvement: Add Coverage reporting Apr 27, 2019
@codexetreme
Copy link

Hey guys, I have just discovered this project and I gotta say I love it :) ... Can I help out by adding some tests and/or setting up CI/CD?? I will need some guidance regarding what are the end goals of this issue

@cool-RR
Copy link
Owner

cool-RR commented May 2, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants