Skip to content

Commit

Permalink
fix: multi-line conditions used to ruin branch descriptions. #1875
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Dec 22, 2024
1 parent 2d04835 commit 522c352
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ upgrading your version of coverage.py.
Unreleased
----------

- Fix: some descriptions of missing branches in HTML and LCOV reports were
incorrect for multi-line conditions, as reported in `issue 1875`_. This is
now fixed.

- Fix: Python 3.14 `defers evaluation of annotations <pep649_>`_ by moving them
into separate code objects. That code is rarely executed, so coverage.py
would mark them as missing, as reported in `issue 1908`_. Now they are
Expand All @@ -33,6 +37,7 @@ Unreleased
understand the problem or the solution, but ``git bisect`` helped find it,
and now it's fixed.

.. _issue 1875: https://github.com/nedbat/coveragepy/issues/1875
.. _issue 1902: https://github.com/nedbat/coveragepy/issues/1902
.. _issue 1908: https://github.com/nedbat/coveragepy/issues/1908
.. _pep649: https://docs.python.org/3.14/whatsnew/3.14.html#pep-649-deferred-evaluation-of-annotations
Expand Down
2 changes: 2 additions & 0 deletions coverage/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ def add_arc(
action_msg: str | None = None,
) -> None:
"""Add an arc, including message fragments to use if it is missing."""
start = self.multiline.get(start, start)
end = self.multiline.get(end, end)
if self.debug: # pragma: debugging
print(f"Adding possible arc: ({start}, {end}): {missing_cause_msg!r}, {action_msg!r}")
print(short_stack(), end="\n\n")
Expand Down
14 changes: 14 additions & 0 deletions tests/test_lcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,17 @@ def test_always_raise(self) -> None:
""")
actual_result = self.get_lcov_report_content()
assert expected_result == actual_result

def test_multiline_conditions(self) -> None:
self.make_file("multi.py", """\
def fun(x):
if (
x
):
print("got here")
""")
cov = coverage.Coverage(source=".", branch=True)
self.start_import_stop(cov, "multi")
cov.lcov_report()
lcov = self.get_lcov_report_content()
assert "BRDA:2,0,return from function 'fun',-" in lcov

0 comments on commit 522c352

Please sign in to comment.