Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zackw opened this issue Oct 9, 2024 · 2 comments
Closed

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

zackw opened this issue Oct 9, 2024 · 2 comments
Labels
bug Something isn't working fixed

Comments

@zackw
Copy link
Contributor

zackw commented Oct 9, 2024

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.
@nedbat
Copy link
Owner

nedbat commented Oct 10, 2024

Fixed in commit 474a363

@nedbat nedbat closed this as completed Oct 10, 2024
@nedbat nedbat added the fixed label Oct 10, 2024
@nedbat
Copy link
Owner

nedbat commented Oct 13, 2024

This is now released as part of coverage 7.6.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants