Skip to content

Commit dfa0520

Browse files
authored
handle NoSource exception for coverage (#24441)
fixes #24308
1 parent 4c32b96 commit dfa0520

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

python_files/vscode_pytest/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,19 @@ def pytest_sessionfinish(session, exitstatus):
442442
if is_coverage_run == "True":
443443
# load the report and build the json result to return
444444
import coverage
445+
from coverage.exceptions import NoSource
445446

446447
cov = coverage.Coverage()
447448
cov.load()
449+
448450
file_set: set[str] = cov.get_data().measured_files()
449451
file_coverage_map: dict[str, FileCoverageInfo] = {}
450452
for file in file_set:
451-
analysis = cov.analysis2(file)
453+
try:
454+
analysis = cov.analysis2(file)
455+
except NoSource:
456+
# as per issue 24308 this best way to handle this edge case
457+
continue
452458
lines_executable = {int(line_no) for line_no in analysis[1]}
453459
lines_missed = {int(line_no) for line_no in analysis[3]}
454460
lines_covered = lines_executable - lines_missed

0 commit comments

Comments
 (0)