-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
Regression in branch coverage using Coverage 7.6.3 on Python 3.12+ #1880
Comments
Thanks, I can reproduce it. It seems to have been introduced with 7.6.2. |
I have a very similar issue. False positive in a for loop inside a context manager. coverage 7.6.1 worked correctly. 7.6.2 and 7.6.3 fail. The difference is that it shows up with python 3.13, but not with python 3.12. The bug shows up in
And can be reproduced using:
|
@udifuchs Thanks, but I'm not sure I have enough information to reproduce. When I clone your repo and checkout that branch, I get two test failures:
Full output
|
The walrus was a different animal: a red herring. The key here was the grouped from contextlib import nullcontext
import random
rolled = set()
with nullcontext() as x:
while random.random() < .99:
rolled.add(1)
print("Done with 1")
with (
nullcontext() as x,
):
while random.random() < .99: # line 16
rolled.add(2)
print("Done with 2") # line 19
with (
nullcontext() as x,
nullcontext() as y,
):
while random.random() < .99: # line 25
rolled.add(3)
print("Done with 3") # line 28
assert rolled == {1, 2, 3} Running this produces this report:
Even having just one context manager, the parenthesized syntax causes the problem... Now to debug. |
Fixed in commit b8c236a. |
Bah! What have parentheses done for us lately? :-P Thanks for the fix, @nedbat. |
This is now released as part of coverage 7.6.4. |
I noticed that you are using macos. Apparently, my tests did not work on macos. Here is a branch that fixes that: I don't have access to macos, but here is a successful run with github actions: But the real issue is that this bug still shows up with python 3.12.3. The tests in coverage.py fail when run with python 3.12.3. |
@udifuchs is your problem fixed by coverage 7.6.4? |
No. With coverage 7.6.4 python 3.12.3 still has the same bug. It is reproduced here: It can also be reproduced by running coveragepy test with python 3.12.3. |
I see what you mean. 3.12.3 shows that problem. So do 3.12.4 and 3.12.5. But 3.12.6 and 3.12.7 do not. Can you upgrade your Python? |
I updated coverage.py to decide between 3.12.5 and 3.12.6, so it will work properly with 3.12.3 now. But it hasn't been released yet. Install from git to try it out. |
I installed from git coveragepy version 7.6.5a0.dev1 and it works correctly with python 3.12.3. The reason I am using python 3.12.3 is that this is the packaged version in Ubuntu 24.04. |
Describe the bug
Coverage 7.6.3 appears to have introduced a regression in the calculation of branch coverage related to the handling of while loops inside context managers.
To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
Observed using 3.12.7 and 3.13.0. It doesn't appear in 3.11 or earlier.
coverage debug sys
is helpful.7.6.3. The problem doesn't exist in 7.6.1.
pip freeze
is helpful.The problem has been found in this dependabot update on Briefcase, which bumps coverage.py from 7.6.1 to 7.6.3.
git clone
,pip install
, and so on. Explain like we're five!$ git clone [email protected]:beeware/briefcase.git
$ cd briefcase
$ git checkout -b coverage-7.6.3 origin/dependabot/pip/coverage-toml--7.6.3
$ python3.12 -m venv venv
$ source venv/bin/activate
(venv) $ pip install tox
$ tox -m test312
This will run the full test suite, reporting 2 branch coverage misses:
Expected behavior
If you omit the
git checkout -b ...
line, the main branch uses 7.6.1, and shows 100% coverage.Additional context
It seems likely this is related to #1876, and commit 378c321.
Both of the new "missing" branches follow the same basic pattern of a while loop with a walrus operator, inside a context manager:
https://github.com/beeware/briefcase/blob/563c6acd7b0875ee3f8e808c70065a10c077ed05/src/briefcase/platforms/iOS/xcode.py#L525-L528
https://github.com/beeware/briefcase/blob/563c6acd7b0875ee3f8e808c70065a10c077ed05/src/briefcase/platforms/iOS/xcode.py#L541-L544
Unfortunately, I haven't had any luck reducing this to a simpler example case.
The text was updated successfully, but these errors were encountered: