Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

switch to use file path as key in building test tree #24697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions 37 python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def build_test_tree(session: pytest.Session) -> TestNode:
"""
session_node = create_session_node(session)
session_children_dict: dict[str, TestNode] = {}
file_nodes_dict: dict[Any, TestNode] = {}
file_nodes_dict: dict[str, TestNode] = {}
class_nodes_dict: dict[str, TestNode] = {}
function_nodes_dict: dict[str, TestNode] = {}

Expand Down Expand Up @@ -549,11 +549,13 @@ def build_test_tree(session: pytest.Session) -> TestNode:
function_test_node["children"].append(test_node)
# Check if the parent node of the function is file, if so create/add to this file node.
if isinstance(test_case.parent, pytest.File):
# calculate the parent path of the test case
parent_path = get_node_path(test_case.parent)
try:
parent_test_case = file_nodes_dict[test_case.parent]
parent_test_case = file_nodes_dict[os.fspath(parent_path)]
except KeyError:
parent_test_case = create_file_node(test_case.parent)
file_nodes_dict[test_case.parent] = parent_test_case
parent_test_case = create_file_node(parent_path)
file_nodes_dict[os.fspath(parent_path)] = parent_test_case
if function_test_node not in parent_test_case["children"]:
parent_test_case["children"].append(function_test_node)
# If the parent is not a file, it is a class, add the function node as the test node to handle subsequent nesting.
Expand Down Expand Up @@ -585,22 +587,24 @@ def build_test_tree(session: pytest.Session) -> TestNode:
else:
ERRORS.append(f"Test class {case_iter} has no parent")
break
parent_path = get_node_path(parent_module)
# Create a file node that has the last class as a child.
try:
test_file_node: TestNode = file_nodes_dict[parent_module]
test_file_node: TestNode = file_nodes_dict[os.fspath(parent_path)]
except KeyError:
test_file_node = create_file_node(parent_module)
file_nodes_dict[parent_module] = test_file_node
test_file_node = create_file_node(parent_path)
file_nodes_dict[os.fspath(parent_path)] = test_file_node
# Check if the class is already a child of the file node.
if test_class_node is not None and test_class_node not in test_file_node["children"]:
test_file_node["children"].append(test_class_node)
elif not hasattr(test_case, "callspec"):
# This includes test cases that are pytest functions or a doctests.
parent_path = get_node_path(test_case.parent)
try:
parent_test_case = file_nodes_dict[test_case.parent]
parent_test_case = file_nodes_dict[os.fspath(parent_path)]
except KeyError:
parent_test_case = create_file_node(test_case.parent)
file_nodes_dict[test_case.parent] = parent_test_case
parent_test_case = create_file_node(parent_path)
file_nodes_dict[os.fspath(parent_path)] = parent_test_case
parent_test_case["children"].append(test_node)
created_files_folders_dict: dict[str, TestNode] = {}
for file_node in file_nodes_dict.values():
Expand Down Expand Up @@ -758,18 +762,17 @@ def create_parameterized_function_node(
}


def create_file_node(file_module: Any) -> TestNode:
"""Creates a file node from a pytest file module.
def create_file_node(calculated_node_path: pathlib.Path) -> TestNode:
"""Creates a file node from a path which has already been calculated using the get_node_path function.

Keyword arguments:
file_module -- the pytest file module.
calculated_node_path -- the pytest file path.
"""
node_path = get_node_path(file_module)
return {
"name": node_path.name,
"path": node_path,
"name": calculated_node_path.name,
"path": calculated_node_path,
"type_": "file",
"id_": os.fspath(node_path),
"id_": os.fspath(calculated_node_path),
"children": [],
}

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.