From dfa0520d7a7ec6d20f77acbf54c22bb7e371fe53 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 14 Nov 2024 10:54:50 -0800 Subject: [PATCH] handle NoSource exception for coverage (#24441) fixes https://github.com/microsoft/vscode-python/issues/24308 --- python_files/vscode_pytest/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index d162f8234177..9f02481b344a 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -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