Skip to content

Commit 474a363

Browse files
committed
fix: didn't-ectomy. #1873
1 parent 5229fc3 commit 474a363

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGES.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ upgrading your version of coverage.py.
2323
Unreleased
2424
----------
2525

26-
Nothing yet.
26+
- Fix: the missing branch message about not exiting a module had an extra
27+
"didn't," as described in `issue 1873`_. This is now fixed.
28+
29+
.. _issue 1873: https://github.com/nedbat/coveragepy/issues/1873
2730

2831

2932
.. start-releases

coverage/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ def _code_object__Module(self, node: ast.Module) -> None:
719719
if node.body:
720720
exits = self.process_body(node.body)
721721
for xit in exits:
722-
self.add_arc(xit.lineno, -start, xit.cause, "didn't exit the module")
722+
self.add_arc(xit.lineno, -start, xit.cause, "exit the module")
723723
else:
724724
# Empty module.
725725
self.add_arc(start, -start)

tests/test_arcs.py

+13
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,19 @@ def f(x):
323323
expected = "line 3 didn't jump to the function exit"
324324
assert self.get_missing_arc_description(cov, 3, -2) == expected
325325

326+
def test_leaving_module(self) -> None:
327+
cov = self.check_coverage("""\
328+
print(a := 1)
329+
if a == 1:
330+
print(3)
331+
""",
332+
branchz="2. 23",
333+
branchz_missing="2.",
334+
)
335+
assert self.stdout() == "1\n3\n"
336+
expected = "line 2 didn't exit the module because the condition on line 2 was always true"
337+
assert self.get_missing_arc_description(cov, 2, -1) == expected
338+
326339
def test_with_with_lambda(self) -> None:
327340
self.check_coverage("""\
328341
from contextlib import nullcontext

0 commit comments

Comments
 (0)