Comments (10)
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.
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.
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.
@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.
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.
Thanks Ned!
from pysnooper.
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 theenvlist
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.
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.
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.
from pysnooper.
Related Issues (20)
- Snoop recursively, but only in my code. HOT 2
- print value of a claas var HOT 1
- [feature request] Add command line color output for Windows HOT 7
- SOURCE IS UNAVAILABLE HOT 8
- Feature request: python -m pysnooper user_script.py HOT 4
- Compatibility issue with Debugger in Visual Studio Code HOT 2
- Print("come") HOT 1
- compatiblity with python 3.12 HOT 7
- No variable output from the last line HOT 3
- Can not install it in Kaggle platform HOT 1
- `return` event line missing when exception occurred HOT 9
- new features request/discussion HOT 2
- Add Callback HOT 1
- Fix the CI HOT 4
- Deactivate all snooping except explicitly specified "watch"es HOT 3
- snoop entire file or program HOT 3
- Evaluate using `sys.monitoring` to make PySnooper faster
- [feature] only trace functions in specific files HOT 1
- about using multiprocessing
- Please add support for async functions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysnooper.