-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
continue marked as not covered #198
Comments
Original comment by Jean-Tiare Le Bigot (Bitbucket: jtlebigot, GitHub: Unknown) I ran into a similar use case with this snippet from ddbmock project
I used "# pragma: no cover" as workaround for the stats after checking it is actually reached. This is annoying but really not critical to me. Thanks for this lib btw. |
Original comment by Daniel Black (Bitbucket: dan_black, GitHub: Unknown) Similar to Jean-Tiare's example here's an isolated case: continue is reached with example(4)
|
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren) And likewise for this code:
The continue is reached for 'c' and 'd'. |
Unfortunately, this is not a bug in coverage.py. All of these examples are cases where CPython's peephole optimizer replaces a jump to a continue with a jump to the top of the loop, so the continue line is never actually executed, even though its effects are seen. If you believe as I do that it would be useful to have a way to disable the peephole optimizer so that these sorts of analyses would give useful results, comment on this CPython ticket: http://bugs.python.org/issue2506 "Add mechanism to disable optimizations". |
Issue #254 was marked as a duplicate of this issue. |
If you have an idea of how to detect that, I'm all ears. |
Original comment by Marc Schlaich (Bitbucket: schlamar, GitHub: schlamar) @nedbat Actually I find the behavior of Python in such a case pretty good regarding code coverage. Consider
If you run this with IMO coverage should apply this even to all if conditions. If a if condition is only partly evaluated it should count as not covered (not sure if this is possible, though). |
@schlamar I appreciate your support for the current behavior of coverage.py in this case, but it's pretty hard to argue that it is correct. The fact that it works out for your case doesn't change the fact that the continue line is executed, but is marked as not covered. |
Original comment by Sei Lisa (Bitbucket: Sei_Lisa, GitHub: Unknown) The attached is a proof of concept of what I meant. It successfully detects my test case and my real use case where I first ran into this issue, but not the OP's because the OP's jumps are conditional, so it's not known to be dead code unless the constants are analyzed. |
BTW: A recent thread in Python-Ideas (starting here: https://mail.python.org/pipermail/python-ideas/2014-May/027893.html) approved a possible change to Python to make disabling the optimizer possible. |
@Sei_Lisa I see what you mean about the unreachable blocks. I'll have to think about whether that is a good way to approach this or not. For example, this code will also have an unreachable block:
but I'm not sure I want to just write off that print statement. I think I'd like to flag it as uncovered. |
Original comment by Sei Lisa (Bitbucket: Sei_Lisa, GitHub: Unknown) @nedbat Yes, while I initially developed it trying to come up with some kind of solution for this issue, later I thought that it had some value by itself. It can be just a different category of line: no code, covered, uncovered, unreachable. Maybe I should instead open it as a feature request in a separate issue, as this one is related but not really the same thing? |
Issue #497 was marked as a duplicate of this issue. |
Issue #593 was marked as a duplicate of this issue. |
Issue #594 was marked as a duplicate of this issue. |
Issue #598 was marked as a duplicate of this issue. |
I'm not sure. Release notes still doesn't mention it.
Sure, my biggest project has ~20 workarounds for this issue - I'll try run coverage tests on the 3.10 and report if problem persist. |
The What's New is being updated: python/cpython#24892 |
Due to an optimization in CPython that is amended in 3.10, coverage.py is sometimes unable to determine the coverage of continue statements in branches. See: nedbat/coveragepy#198 Adding a no-op like a print or an empty statement would solve the coverage issue, but I've opted to just ignore the line. This should be tested and the line removed when the site is updated to Python 3.10.
Synthesize into single if-elif-else block and add pragmas for no coverage where continue is called, see: nedbat/coveragepy#198
I've confirmed that the lines are in fact covered by raising errors from them. This relates to a long standing bug in CPython that Coverage is unable to work around, but which is apparently fixed in Python 3.10: nedbat/coveragepy#198 (comment)
…`Model` of module `modeltools` slightly to avoid `coveragepy` wrongly reporting an uncovered `continue` line. Due to CPython's peephole optimizer, see nedbat/coveragepy#198).
…onnect_subgroup` of class `Model` of module `modeltools` for which `coveragepy` otherwise reports missing coverage. Due to CPython's peephole optimizer, see nedbat/coveragepy#198.
Originally reported by Anonymous
It seems that if:
the continue statement is marked as missing which is not true. Especially in a "if True or True:" case.
continue.py:
$ python --version
Python 2.7.2+
Run as:
$ coverage run continue.py && coverage html
The text was updated successfully, but these errors were encountered: