Giter VIP home page Giter VIP logo

Comments (10)

cool-RR avatar cool-RR commented on August 13, 2024

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

from pysnooper.

cool-RR avatar cool-RR commented on August 13, 2024

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?

from pysnooper.

nedbat avatar nedbat commented on August 13, 2024

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.

from pysnooper.

cool-RR avatar cool-RR commented on August 13, 2024

@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?

from pysnooper.

nedbat avatar nedbat commented on August 13, 2024

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.

from pysnooper.

cool-RR avatar cool-RR commented on August 13, 2024

Thanks Ned!

from pysnooper.

bittner avatar bittner commented on August 13, 2024

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.

from pysnooper.

cool-RR avatar cool-RR commented on August 13, 2024

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.

from pysnooper.

codexetreme avatar codexetreme commented on August 13, 2024

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

from pysnooper.

cool-RR avatar cool-RR commented on August 13, 2024

from pysnooper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.