Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e011a5

Browse files
committed
test: add a test for #1685
Also, analysis.excluded is already a set, so it's faster to use it as-is than to sort it into a list. Also also, analysis.missing has already had excluded lines removed from it, so no need to check it.
1 parent 788dace commit 3e011a5

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

CHANGES.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ development at the same time, such as 4.5.x and 5.0.
2020
Unreleased
2121
----------
2222

23-
Nothing yet.
23+
- The ``coverage lcov`` command ignored the ``[report] exclude_lines`` and
24+
``[report] exclude_also`` settings (`issue 1684`_). This is now fixed,
25+
thanks `Jacqueline Lee <pull 1685_>`_.
26+
27+
.. _issue 1684: https://github.com/nedbat/coveragepy/issues/1684
28+
.. _pull 1685: https://github.com/nedbat/coveragepy/pull/1685
2429

2530

2631
.. scriv-start-here

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Ionel Cristian Mărieș
9898
Ivan Ciuvalschii
9999
J. M. F. Tsang
100100
JT Olds
101+
Jacqueline Lee
101102
Jakub Wilk
102103
Janakarajan Natarajan
103104
Jerin Peter George

coverage/lcovreport.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ def get_lcov(self, fr: FileReporter, analysis: Analysis, outfile: IO[str]) -> No
6262
outfile.write("TN:\n")
6363
outfile.write(f"SF:{fr.relative_filename()}\n")
6464
source_lines = fr.source().splitlines()
65-
sorted_excluded = sorted(analysis.excluded)
6665
for covered in sorted(analysis.executed):
67-
if covered in sorted_excluded:
66+
if covered in analysis.excluded:
6867
# Do not report excluded as executed
6968
continue
7069
# Note: Coverage.py currently only supports checking *if* a line
@@ -85,9 +84,8 @@ def get_lcov(self, fr: FileReporter, analysis: Analysis, outfile: IO[str]) -> No
8584
outfile.write(f"DA:{covered},1,{line_hash(line)}\n")
8685

8786
for missed in sorted(analysis.missing):
88-
if missed in sorted_excluded:
89-
# Do not report excluded as missing
90-
continue
87+
# We don't have to skip excluded lines here, because `missing`
88+
# already doesn't have them.
9189
assert source_lines
9290
line = source_lines[missed-1]
9391
outfile.write(f"DA:{missed},0,{line_hash(line)}\n")

tests/test_lcov.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,39 @@ def test_empty_init_files(self) -> None:
279279
""")
280280
actual_result = self.get_lcov_report_content()
281281
assert expected_result == actual_result
282+
283+
def test_excluded_lines(self) -> None:
284+
self.make_file(".coveragerc", """\
285+
[report]
286+
exclude_lines = foo
287+
""")
288+
self.make_file("runme.py", """\
289+
s = "Hello 1"
290+
t = "foo is ignored 2"
291+
if s.upper() == "BYE 3":
292+
i_am_missing_4()
293+
foo_is_missing_5()
294+
print("Done 6")
295+
# foo 7
296+
# line 8
297+
""")
298+
cov = coverage.Coverage(source=".", branch=True)
299+
self.start_import_stop(cov, "runme")
300+
cov.lcov_report()
301+
expected_result = textwrap.dedent("""\
302+
TN:
303+
SF:runme.py
304+
DA:1,1,nWfwsz0pRTEJrInVF+xNvQ
305+
DA:3,1,uV4NoIauDo5LCti6agX9sg
306+
DA:6,1,+PfQRgSChjQOGkA6MArMDg
307+
DA:4,0,GR4ThLStnqpcZvm3alfRaA
308+
LF:4
309+
LH:3
310+
BRDA:4,0,0,-
311+
BRDA:6,0,1,1
312+
BRF:2
313+
BRH:1
314+
end_of_record
315+
""")
316+
actual_result = self.get_lcov_report_content()
317+
assert expected_result == actual_result

0 commit comments

Comments
 (0)