Skip to content

Commit

Permalink
fix: didn't-ectomy. #1873
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Oct 10, 2024
1 parent 5229fc3 commit 474a363
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ upgrading your version of coverage.py.
Unreleased
----------

Nothing yet.
- Fix: the missing branch message about not exiting a module had an extra
"didn't," as described in `issue 1873`_. This is now fixed.

.. _issue 1873: https://github.com/nedbat/coveragepy/issues/1873


.. start-releases
Expand Down
2 changes: 1 addition & 1 deletion coverage/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def _code_object__Module(self, node: ast.Module) -> None:
if node.body:
exits = self.process_body(node.body)
for xit in exits:
self.add_arc(xit.lineno, -start, xit.cause, "didn't exit the module")
self.add_arc(xit.lineno, -start, xit.cause, "exit the module")
else:
# Empty module.
self.add_arc(start, -start)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_arcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,19 @@ def f(x):
expected = "line 3 didn't jump to the function exit"
assert self.get_missing_arc_description(cov, 3, -2) == expected

def test_leaving_module(self) -> None:
cov = self.check_coverage("""\
print(a := 1)
if a == 1:
print(3)
""",
branchz="2. 23",
branchz_missing="2.",
)
assert self.stdout() == "1\n3\n"
expected = "line 2 didn't exit the module because the condition on line 2 was always true"
assert self.get_missing_arc_description(cov, 2, -1) == expected

def test_with_with_lambda(self) -> None:
self.check_coverage("""\
from contextlib import nullcontext
Expand Down

0 comments on commit 474a363

Please sign in to comment.