Skip to content

Commit

Permalink
handle NoSource exception for coverage (#24441)
Browse files Browse the repository at this point in the history
fixes #24308
  • Loading branch information
eleanorjboyd authored Nov 14, 2024
1 parent 4c32b96 commit dfa0520
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,19 @@ def pytest_sessionfinish(session, exitstatus):
if is_coverage_run == "True":
# load the report and build the json result to return
import coverage
from coverage.exceptions import NoSource

cov = coverage.Coverage()
cov.load()

file_set: set[str] = cov.get_data().measured_files()
file_coverage_map: dict[str, FileCoverageInfo] = {}
for file in file_set:
analysis = cov.analysis2(file)
try:
analysis = cov.analysis2(file)
except NoSource:
# as per issue 24308 this best way to handle this edge case
continue
lines_executable = {int(line_no) for line_no in analysis[1]}
lines_missed = {int(line_no) for line_no in analysis[3]}
lines_covered = lines_executable - lines_missed
Expand Down

0 comments on commit dfa0520

Please sign in to comment.