Skip to content

Commit 84280b0

Browse files
authored
fix regression with import packaging for branch coverage (#25070)
fixes #25044
1 parent 4367614 commit 84280b0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

python_files/unittestadapter/execution.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from types import TracebackType
1313
from typing import Dict, List, Optional, Set, Tuple, Type, Union
1414

15-
from packaging.version import Version
16-
1715
# Adds the scripts directory to the PATH as a workaround for enabling shell for test execution.
1816
path_var_name = "PATH" if "PATH" in os.environ else "Path"
1917
os.environ[path_var_name] = (
@@ -326,6 +324,13 @@ def send_run_data(raw_data, test_run_pipe):
326324
)
327325
import coverage
328326

327+
# insert "python_files/lib/python" into the path so packaging can be imported
328+
python_files_dir = pathlib.Path(__file__).parent.parent
329+
bundled_dir = pathlib.Path(python_files_dir / "lib" / "python")
330+
sys.path.append(os.fspath(bundled_dir))
331+
332+
from packaging.version import Version
333+
329334
coverage_version = Version(coverage.__version__)
330335
# only include branches if coverage version is 7.7.0 or greater (as this was when the api saves)
331336
if coverage_version >= Version("7.7.0"):

python_files/vscode_pytest/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from typing import TYPE_CHECKING, Any, Dict, Generator, Literal, TypedDict
1414

1515
import pytest
16-
from packaging.version import Version
1716

1817
if TYPE_CHECKING:
1918
from pluggy import Result
@@ -443,6 +442,13 @@ def pytest_sessionfinish(session, exitstatus):
443442
# load the report and build the json result to return
444443
import coverage
445444

445+
# insert "python_files/lib/python" into the path so packaging can be imported
446+
python_files_dir = pathlib.Path(__file__).parent.parent
447+
bundled_dir = pathlib.Path(python_files_dir / "lib" / "python")
448+
sys.path.append(os.fspath(bundled_dir))
449+
450+
from packaging.version import Version
451+
446452
coverage_version = Version(coverage.__version__)
447453
global INCLUDE_BRANCHES
448454
# only include branches if coverage version is 7.7.0 or greater (as this was when the api saves)

0 commit comments

Comments
 (0)