Skip to content

Commit 0767373

Browse files
committed
fix regression with import packaging for branch coverage
1 parent e709012 commit 0767373

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

python_files/unittestadapter/execution.py

Lines changed: 8 additions & 5 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,9 +324,14 @@ def send_run_data(raw_data, test_run_pipe):
326324
)
327325
import coverage
328326

329-
coverage_version = Version(coverage.__version__)
330-
# only include branches if coverage version is 7.7.0 or greater (as this was when the api saves)
331-
if coverage_version >= Version("7.7.0"):
327+
def parse_version(version_str):
328+
try:
329+
return tuple(int(part) for part in version_str.split(".") if part.isdigit())
330+
except ValueError:
331+
return (0, 0, 0)
332+
333+
# only include branches if coverage version is 7.7.0 or greater
334+
if parse_version(coverage.__version__) >= (7, 7, 0):
332335
include_branches = True
333336

334337
source_ar: List[str] = []

python_files/vscode_pytest/__init__.py

Lines changed: 9 additions & 4 deletions
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,10 +442,16 @@ def pytest_sessionfinish(session, exitstatus):
443442
# load the report and build the json result to return
444443
import coverage
445444

446-
coverage_version = Version(coverage.__version__)
447445
global INCLUDE_BRANCHES
448-
# only include branches if coverage version is 7.7.0 or greater (as this was when the api saves)
449-
if coverage_version < Version("7.7.0") and INCLUDE_BRANCHES:
446+
447+
def parse_version(version_str):
448+
try:
449+
return tuple(int(part) for part in version_str.split(".") if part.isdigit())
450+
except ValueError:
451+
return (0, 0, 0)
452+
453+
# only include branches if coverage version is 7.7.0 or greater
454+
if parse_version(coverage.__version__) < (7, 7, 0) and INCLUDE_BRANCHES:
450455
print(
451456
"Plugin warning[vscode-pytest]: Branch coverage not supported in this coverage versions < 7.7.0. Please upgrade coverage package if you would like to see branch coverage."
452457
)

0 commit comments

Comments
 (0)