-
-
Notifications
You must be signed in to change notification settings - Fork 439
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
Coverage of assert statements. #160
Comments
Coverage.py can't influence what code paths you execute, it merely monitors what code paths are executed. It's up to you to design a test suite that exercises all of the test cases you need tested. Maybe I don't understand your problem? |
I see what you mean. There are a few things that come to mind:
|
Original comment by Anonymous Thanks for the fast answer.
Is there an easy way to expose this, and maybe enable this behavior with a command line option?
This is a valid point, but I like using asserts since they are very concise and easily removed with python -OO for production. I'll be happy to take a stab at the code but since I'm not "in" the codebase right now, I would appreciate pointers / strategies on how to do this optimally (i.e. that will fit your requirements to get merged). Thanks again. |
Earlier I said "I don't know why it doesn't already do this." It's because the compiled code is all associated with the same source line. For example, coverage also can't do branch coverage for a one-line if like this:
So something significant would have to change in coverage.py for it to be able to detect whether asserts went both ways. Possibilities include: Preprocess the source to change assert statementsPreprocess the bytecode to fiddle with the line numbersChange the trace function to record exceptions raisedNone of these are simple, and represent a major new feature in coverage.py. |
Hmm, I'm reluctant to start transforming source code, especially since it would throw off the source code reporting. I'm not sure any of these approaches is a good idea, but #3 fits the current code base best. I'm honestly not sure what information is available in the trace function for tracking exceptions, but you can give it a try. Look in collector.py, line 96 to get started. |
Original comment by Felipe (Bitbucket: felipeochoa, GitHub: felipeochoa) Not at all familiar with the Add a |
Originally reported by npinto (Bitbucket: npinto, GitHub: npinto)
Hello,
I'm trying to use coverage.py to get the coverage (duh!) of both outcomes in assert statements [1]. Am I missing something or is this not (yet) possible?
Let me know how can I contribute.
Nicolas
[1] In our code base we use many (possibly very slow) asserts during development, this is really useful in production for performance reasons since we can use python -OO to remove the execution of asserts.
The text was updated successfully, but these errors were encountered: