You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[internal] Generator-expression exit arcs aren't always filtered out of executed_branch_arcs #1852
(Any use of a generator expression in the controlling condition of an if should provoke the problem, albeit I have not tried it with a multi-line controlling condition.)
If I run this snippet as coverage run --branch test.py or coverage run --branch test.py nonoption it produces this arc table:
sqlite3 -table .coverage 'select fromno, tono from arc order by fromno, tono'
fromno
tono
-4
4
-3
4
-1
1
1
3
3
7
4
-4
4
-3
4
4
7
-1
If I run it as coverage run -branch test.py -flag I get this arc table instead:
fromno
tono
-4
4
-3
4
-1
1
1
3
3
7
4
4
4
5
5
-3
7
-1
The problem is with the arc (4, -4), which is (as far as I can tell) the exit arc for the generator expression. The analysis code is supposed to be filtering this arc out as uninteresting, but either it only does this for missing_branch_arcs() and not for executed_branch_arcs(), or there's a bug in its handling of this construct. When the input is the first of the above two arc tables, executed_branch_arcs()[4] is {-4, -3, 4}.
The HTML report generator doesn't care about this because it only looks at missing arcs, but the LCOV report generator looks at both missing and executed arcs and trips over the (4, -4) edge. With the code in #1851, the difference in coverage lcov output for the above two arc tables is
Are you sure you are running the code from the tip of master when measuring coverage? There should no longer be a (4, -4) arc in the data, as of commit 2afe04d:
2afe04d1 2024-08-26 refactor: don't test arcs, test branches
Yes, I'm sure. I added three tests to the testsuite specifically for this; all of the test failures on the most recent push for #1851 are because in two out of three cases the equivalent of the (4, -4) arc is visible to the lcov reporter.
Fine-tuned the tests a little more in commit 402bee8. Given this function
deffoo(a):
ifany(x>0forxina):
print(f"{a!r} has positives")
the genexpr exit arc is pruned by the analysis engine if and only if the arc exiting the whole function is never taken. For example, if foo is never called at all, or if the only call is foo([1]), then the genexpr exit arc will be pruned, but if the only call is foo([0]) or if it's called twice as foo([0]) and foo([1]) then the genexpr exit arc will not be pruned.
Thanks for your patience; have only just now had a chance to test the new code against the full application that prompted this report. It generally looks good. There are no longer any cases where the LCOV report includes three or more branch destinations for a single line. There are also no longer any cases where negative arc destination numbers appear in the LCOV output.
I do see a few places where the generic "jump to the function exit" text appears in the LCOV output. I will file follow-up bugs for these later today. I think you can go ahead and mark this issue as resolved in 7.6.2.
Activity
nedbat commentedon Sep 15, 2024
Are you sure you are running the code from the tip of master when measuring coverage? There should no longer be a (4, -4) arc in the data, as of commit 2afe04d:
Split up test_multiple_exit_branches into 3 tests exercising coverage…
zackw commentedon Sep 16, 2024
Yes, I'm sure. I added three tests to the testsuite specifically for this; all of the test failures on the most recent push for #1851 are because in two out of three cases the equivalent of the (4, -4) arc is visible to the lcov reporter.
add a fourth case to the tests for coveragepy#1852
zackw commentedon Sep 16, 2024
Fine-tuned the tests a little more in commit 402bee8. Given this function
the genexpr exit arc is pruned by the analysis engine if and only if the arc exiting the whole function is never taken. For example, if
foois never called at all, or if the only call isfoo([1]), then the genexpr exit arc will be pruned, but if the only call isfoo([0])or if it's called twice asfoo([0])andfoo([1])then the genexpr exit arc will not be pruned.CI test results for 402bee8
Split up test_multiple_exit_branches into 3 tests exercising coverage…
add a fourth case to the tests for coveragepy#1852
fix: lcov report improvements #1850 (#1851)
nedbat commentedon Oct 3, 2024
Is this issue done now also?
zackw commentedon Oct 9, 2024
Thanks for your patience; have only just now had a chance to test the new code against the full application that prompted this report. It generally looks good. There are no longer any cases where the LCOV report includes three or more branch destinations for a single line. There are also no longer any cases where negative arc destination numbers appear in the LCOV output.
I do see a few places where the generic "jump to the function exit" text appears in the LCOV output. I will file follow-up bugs for these later today. I think you can go ahead and mark this issue as resolved in 7.6.2.
nedbat commentedon Oct 9, 2024
This is now fixed as part of coverage 7.6.2.