Skip to content

Extra "didn't" in arc description for exiting the module #1873

Closed
@zackw

Description

@zackw

Describe the bug

When this simple Python script is analyzed for branch coverage...

#! /usr/bin/python3

print("Executed unconditionally")

if __name__ == "__main__":
    print("Executed if __name__ == __main__")

... both the HTML and LCOV reporters describe the non-executed branch that skips over print("Executed if __name__ == __main__") with an extra "didn't."

top-level-if-1.lcov
SF:top-level-if-1.py
DA:3,1
DA:5,1
DA:6,1
LF:3
LH:3
BRDA:5,0,jump to line 6,1
BRDA:5,0,didn't exit the module,0
BRF:2
BRH:1
end_of_record
top-level-if-1_py.html excerpt
<main id="source">
    <p class="pln"><span class="n"><a id="t1" href="#t1">1</a></span><span class="t"><span class="com"># </span>&nbsp;</span><span class="r"></span></p>
    <p class="pln"><span class="n"><a id="t2" href="#t2">2</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p class="run"><span class="n"><a id="t3" href="#t3">3</a></span><span class="t"><span class="nam">print</span><span class="op">(</span><span class="str">"Executed unconditionally"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p class="pln"><span class="n"><a id="t4" href="#t4">4</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p class="par run show_par"><span class="n"><a id="t5" href="#t5">5</a></span><span class="t"><span class="key">if</span> <span class="nam">__name__</span> <span class="op">==</span> <span class="str">"__main__"</span><span class="op">:</span>&nbsp;</span><span class="r"><span class="annotate short">5&#x202F;&#x219B;&#x202F;exit</span><span class="annotate long">line 5 didn't didn't exit the module because the condition on line 5 was always true</span></span></p>
    <p class="run"><span class="n"><a id="t6" href="#t6">6</a></span><span class="t">    <span class="nam">print</span><span class="op">(</span><span class="str">"Executed if __name__ == __main__"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
</main>

The problem is with the second BRDA: line in the lcov output:

BRDA:5,0,didn't exit the module,0

and with the long annotation for line 5 in the html output:

<span class="annotate long">line 5 didn't didn't exit the module because the condition on line 5 was always true</span>

Strikethrough indicates text that should be removed.

$ coverage --version
Coverage.py, version 7.6.2 with C extension
$ python3 --version
Python 3.12.6

I imagine this is fallout from the refactoring done to address #1850.

To Reproduce

  1. Copy the script at the beginning of this report to top-level-if-1.py.
  2. coverage run --branch top-level-if-1.py.
  3. coverage lcov -o top-level-if-1.lcov should produce an identical file to top-level-if-1.lcov embedded above.
  4. coverage html should produce (among other things) top-level-if-1_py.html matching the excerpt embedded above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions