Skip to content

"Run Test with Coverage" should catch NoSource exceptions #24308

Open

Description

The root cause of my observations in #24307 (which still deserves its own solution IMHO) is nedbat/coveragepy#1392. Unfortunately, configuring omit alone does not help because this code snipped does not consider it:

# load the report and build the json result to return
import coverage
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)
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
file_info: FileCoverageInfo = {
"lines_covered": list(lines_covered), # list of int
"lines_missed": list(lines_missed), # list of int
}
file_coverage_map[file] = file_info

cov._check_include_omit_etc being private, the extension cannot really know what to check. So I propose replacing

analysis = cov.analysis2(file)

by

try:
    analysis = cov.analysis2(file)
except NoSource:
    continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

area-testingfeature-requestRequest for new features or functionalitytriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions