From 9b4046aab8c4c56510a769121ee0ed07bc406d9a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 21 Oct 2024 20:24:44 -0400 Subject: [PATCH] fix: with-exiting changed in 3.12.6. #1880 --- CHANGES.rst | 4 +++- coverage/env.py | 2 +- tests/test_arcs.py | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 21c143abd..e9fca2bf8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/coverage/env.py b/coverage/env.py index 39ec169c2..4db2f3e0f 100644 --- a/coverage/env.py +++ b/coverage/env.py @@ -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)) diff --git a/tests/test_arcs.py b/tests/test_arcs.py index 3146daf77..e03013be4 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -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("""\ @@ -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."""