Closed ziima closed 1 month ago
We're seeing the same thing with this code: https://github.com/pyca/cryptography/blob/main/tests/x509/test_name.py#L17-L27
https://github.com/pyca/cryptography/actions/runs/11273274929/job/31350177576 shows the coverage output (26->18 is uncovered)
Experiencing this well. I additionally noticed that the branch coverage is only missing on the last of the nested context managers. Extending @ziima's example:
from unittest import TestCase
from contextlib import suppress
class CoverageTest(TestCase):
def test_coverage(self):
with suppress(ValueError):
# Covered correctly
with suppress(ValueError):
pass
# Covered correctly
with suppress(ValueError):
pass
# Missing branch here:
with suppress(ValueError):
pass
expected = (
tuple(b"<content_1>"),
)
I also encountered the issue when the context manager is the last line in the test function, even though removing the expected = ...
statement from the above example results in 100% coverage. An example is here.
Thanks for the clear test cases. This is fixed in commit 378c321ba035400b6091505446844e552d8808d5.
Thanks Ned!
This is now released as part of coverage 7.6.3.
Describe the bug We discovered a regression in branch coverage of nested context processors in 7.6.2.
To Reproduce How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
Affected are 3.10 and 3.11
coverage debug sys
is helpful.7.6.2
pip freeze
is helpful.git clone
,pip install
, and so on. Explain like we're five!Actual behavior
Expected behavior 100% coverage
Additional context Report is fine in:
The branch coverage is highly dependent on the exact code. The missing branch also disappears if the
expected
is reformatted to a single line.