Skip to content

Commit 946562a

Browse files
committed
linting
1 parent 6cd3b23 commit 946562a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

python_files/vscode_pytest/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ 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([file_node["path"], session_node["path"]])
563+
common_parent = os.path.commonpath([os.fspath(file_node["path"]), os.fspath(session_node["path"])])
564564
common_parent_path = pathlib.Path(common_parent)
565565
print("[vscode-pytest]: Session node now set to: ", common_parent)
566566
session_node["path"] = common_parent_path # pathlib.Path
@@ -712,6 +712,9 @@ def build_test_tree(session: pytest.Session) -> TestNode:
712712
test_file_node["children"].append(test_class_node)
713713
elif not hasattr(test_case, "callspec"):
714714
# This includes test cases that are pytest functions or a doctests.
715+
if test_case.parent is None:
716+
ERRORS.append(f"Test case {test_case.name} has no parent")
717+
continue
715718
parent_path = get_node_path(test_case.parent)
716719
try:
717720
parent_test_case = file_nodes_dict[os.fspath(parent_path)]
@@ -930,7 +933,13 @@ def get_node_path(
930933
Returns:
931934
pathlib.Path: The resolved path for the node.
932935
"""
933-
node_path = getattr(node, "path", None) or pathlib.Path(node.fspath)
936+
node_path = getattr(node, "path", None)
937+
if node_path is None:
938+
fspath = getattr(node, "fspath", None)
939+
if fspath is not None:
940+
node_path = pathlib.Path(fspath)
941+
else:
942+
node_path = None
934943

935944
if not node_path:
936945
raise VSCodePytestError(

0 commit comments

Comments
 (0)