File tree 3 files changed +39
-4
lines changed
3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,12 @@ upgrading your version of coverage.py.
23
23
Unreleased
24
24
----------
25
25
26
- Nothing yet.
26
+ - fix: the LCOV report code assumed that a branch line that took no branches
27
+ meant that the entire line was unexecuted. This isn't true in a few cases:
28
+ the line might always raise an exception, or might have been optimized away.
29
+ Fixes `issue 1896 `_.
30
+
31
+ .. _issue 1896 : https://github.com/nedbat/coveragepy/issues/1896
27
32
28
33
29
34
.. start-releases
Original file line number Diff line number Diff line change @@ -118,10 +118,8 @@ def lcov_arcs(
118
118
119
119
if taken == 0 :
120
120
# When _none_ of the out arcs from 'line' were executed,
121
- # this probably means 'line' was never executed at all.
122
- # Cross-check with the line stats.
121
+ # it can mean the line always raised an exception.
123
122
assert len (executed_arcs [line ]) == 0
124
- assert line in analysis .missing
125
123
destinations = [
126
124
(dst , "-" ) for dst in missing_arcs [line ]
127
125
]
Original file line number Diff line number Diff line change @@ -526,3 +526,35 @@ def foo(a):
526
526
""" )
527
527
actual_result = self .get_lcov_report_content ()
528
528
assert expected_result == actual_result
529
+
530
+ def test_always_raise (self ) -> None :
531
+ self .make_file ("always_raise.py" , """\
532
+ try:
533
+ if not_defined:
534
+ print("Yes")
535
+ else:
536
+ print("No")
537
+ except Exception:
538
+ pass
539
+ """ )
540
+ cov = coverage .Coverage (source = "." , branch = True )
541
+ self .start_import_stop (cov , "always_raise" )
542
+ cov .lcov_report ()
543
+ expected_result = textwrap .dedent ("""\
544
+ SF:always_raise.py
545
+ DA:1,1
546
+ DA:2,1
547
+ DA:3,0
548
+ DA:5,0
549
+ DA:6,1
550
+ DA:7,1
551
+ LF:6
552
+ LH:4
553
+ BRDA:2,0,jump to line 3,-
554
+ BRDA:2,0,jump to line 5,-
555
+ BRF:2
556
+ BRH:0
557
+ end_of_record
558
+ """ )
559
+ actual_result = self .get_lcov_report_content ()
560
+ assert expected_result == actual_result
You can’t perform that action at this time.
0 commit comments