-
-
Notifications
You must be signed in to change notification settings - Fork 441
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
python3.8: unable to detect break
in while loop as covered
#772
Comments
The problem here isn't that the opcodes have changed, but that the peephole optimizer has become cleverer. If you look at the bytecode, you see that if start != 1 on line 4, then the jump is to bytecode 36, not bytecode 32. That is, the optimizer recognizes that the if statement could go to a break, which itself goes to the return, so just make the if go straight to the return. This is another instance of the problem first reported over 10 years ago in bpo 2506. The debate there ended long ago, but needs someone to implement a way to disable the peephole optimizer for times when you are running code for analysis rather than performance. Perhaps your voice will help? |
This is a long-running bug in coverage that manifests in many ways. When the peephole optimizer eliminates a part of the code, it doesn't leave a trace that coverage can see, so even if a line's effects are seen, the code shows as uncovered. It appears that this is happening here, but we can disable the optimizer in this test by assigning to a random variable to force the branch to be executed in a way that coverage can see it. We could also add # pragma: nocover here, but I'd like to make sure that this line is seen as covered, since otherwise it may mean that some of our tests are erroneously being treated as folds or gaps. More background reading: - bpo-2506 https://bugs.python.org/issue2506 - nedbat/coveragepy#772
This is a long-running bug in coverage that manifests in many ways. When the peephole optimizer eliminates a part of the code, it doesn't leave a trace that coverage can see, so even if a line's effects are seen, the code shows as uncovered. It appears that this is happening here, but we can disable the optimizer in this test by assigning to a random variable to force the branch to be executed in a way that coverage can see it. We could also add # pragma: nocover here, but I'd like to make sure that this line is seen as covered, since otherwise it may mean that some of our tests are erroneously being treated as folds or gaps. More background reading: - bpo-2506 https://bugs.python.org/issue2506 - nedbat/coveragepy#772
Summary: It turns out that with python 3.8 (platform009 version of python) the coverage of `break` immediately followed by a return is not handled. Turns out to be some peephole optimizer thing: nedbat/coveragepy#772 So, we'll just add `#pragma: no cover` to these statements and cry a little. Reviewed By: justintrudell Differential Revision: D25876993 fbshipit-source-id: 041eca915bbc73a1b7360d5e80f794772d82ba96
1. break statement doesn't gets covered by coverage in py38 onwards due to some optimizations in the peephole optimizer. nedbat/coveragepy#772 Hence, it was excluded from the coverage. 2. Region specific accounts were added apart from default for aws publish to cover all the cases in the code.
…due to peephole optimization. See nedbat/coveragepy#772
Describe the bug
python has changed how loops work in python3.8. there are no longer explicit opcodes for
break
/continue
/ etc. Some of these seem handled in coverage but others are not.To Reproduce
Expected behavior
This is what happens in python3.7:
Additional context
https://bugs.python.org/issue17611 appears to be the bpo that changed this behaviour
I've verified that the
break
is covered by adding aprint(0)
above it, however this causes the break to magically become covered. It only reproduces when there's nothing else in that block.Here's the disassembly from python3.7:
Here's the disassembly from python3.8
The main difference here being line
8
which goes fromBREAK_LOOP
(3.7) toJUMP_ABSOLUTE
(3.8)The text was updated successfully, but these errors were encountered: