Skip to content

Commit c1d50ad

Browse files
committed
fix
1 parent 946562a commit c1d50ad

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

python_files/vscode_pytest/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pathlib
1111
import sys
1212
import traceback
13-
from typing import TYPE_CHECKING, Any, Dict, Generator, Literal, Protocol, TypedDict
13+
from typing import TYPE_CHECKING, Any, Dict, Generator, Literal, Protocol, TypedDict, cast
1414

1515
import pytest
1616

@@ -560,7 +560,9 @@ def construct_nested_folders(
560560
# IMPORTANT: Use session_node["path"] directly as it's already a pathlib.Path object
561561
# Do NOT use get_node_path(session_node["path"]) as get_node_path expects pytest objects,
562562
# not Path objects directly.
563-
common_parent = os.path.commonpath([os.fspath(file_node["path"]), os.fspath(session_node["path"])])
563+
common_parent = os.path.commonpath(
564+
[file_node["path"], session_node["path"]]
565+
)
564566
common_parent_path = pathlib.Path(common_parent)
565567
print("[vscode-pytest]: Session node now set to: ", common_parent)
566568
session_node["path"] = common_parent_path # pathlib.Path
@@ -715,7 +717,17 @@ def build_test_tree(session: pytest.Session) -> TestNode:
715717
if test_case.parent is None:
716718
ERRORS.append(f"Test case {test_case.name} has no parent")
717719
continue
718-
parent_path = get_node_path(test_case.parent)
720+
parent_path = get_node_path(
721+
cast(
722+
pytest.Session
723+
| pytest.Item
724+
| pytest.File
725+
| pytest.Class
726+
| pytest.Module
727+
| HasPathOrFspath,
728+
test_case.parent,
729+
)
730+
)
719731
try:
720732
parent_test_case = file_nodes_dict[os.fspath(parent_path)]
721733
except KeyError:

0 commit comments

Comments
 (0)