Skip to content

Commit

Permalink
fix: with-exiting changed in 3.12.6. #1880
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Oct 22, 2024
1 parent d7d133c commit 9b4046a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ upgrading your version of coverage.py.
Unreleased
----------

Nothing yet.
- fix: fine-tuned the exact Python version (3.12.6) when exiting from ``with``
statements changed how they traced. This affected whether people saw the
fix for `issue 1880`_.


.. start-releases
Expand Down
2 changes: 1 addition & 1 deletion coverage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class PYBEHAVIOR:

# When leaving a with-block, do we visit the with-line exactly,
# or the inner-most context manager?
exit_with_through_ctxmgr = (PYVERSION >= (3, 12))
exit_with_through_ctxmgr = (PYVERSION >= (3, 12, 6))

# Match-case construct.
match_case = (PYVERSION >= (3, 10))
Expand Down
17 changes: 16 additions & 1 deletion tests/test_arcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ def test_multiline_with(self) -> None:
branchz_missing="",
)


def test_multi_multiline_with(self) -> None:
# https://github.com/nedbat/coveragepy/issues/1880
self.check_coverage("""\
Expand All @@ -382,6 +381,22 @@ def test_multi_multiline_with(self) -> None:
branchz_missing="",
)

def test_multi_multiline_with_backslask(self) -> None:
# https://github.com/nedbat/coveragepy/issues/1880
self.check_coverage("""\
import contextlib, itertools
nums = itertools.count()
with contextlib.nullcontext() as x, \\
contextlib.nullcontext() as y, \\
contextlib.nullcontext() as z:
while next(nums) < 6:
y = 7
z = 8
""",
branchz="67 68",
branchz_missing="",
)


class LoopArcTest(CoverageTest):
"""Arc-measuring tests involving loops."""
Expand Down

0 comments on commit 9b4046a

Please sign in to comment.