From bf46284b2c8faa219d4cba2a460c93098b7037da Mon Sep 17 00:00:00 2001 From: George Nikitin <133176081+GeorgeNikitinNV@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:11:01 +1300 Subject: [PATCH] Fix 'coverage.exceptions.NoSource` import to fallback to previous exception path (#24608) Fixes https://github.com/microsoft/vscode-python/issues/24607 --- python_files/vscode_pytest/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index f7ba1d5842ef..561f6e432341 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -442,7 +442,11 @@ def pytest_sessionfinish(session, exitstatus): if is_coverage_run == "True": # load the report and build the json result to return import coverage - from coverage import exceptions + + try: + from coverage.exceptions import NoSource + except ImportError: + from coverage.misc import NoSource cov = coverage.Coverage() cov.load() @@ -462,7 +466,7 @@ def pytest_sessionfinish(session, exitstatus): for file in file_set: try: analysis = cov.analysis2(file) - except exceptions.NoSource: + 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]}