From d4abc23c444dd8580a6e0e803985879135197360 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Wed, 9 Jul 2025 12:02:45 -0700 Subject: [PATCH 1/2] switch to using absolute paths for unittest classes with pytest --- .../expected_discovery_test_output.py | 85 +++++++++++++++---- python_files/vscode_pytest/__init__.py | 3 +- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/python_files/tests/pytestadapter/expected_discovery_test_output.py b/python_files/tests/pytestadapter/expected_discovery_test_output.py index d7e82acc6890..3223970f8315 100644 --- a/python_files/tests/pytestadapter/expected_discovery_test_output.py +++ b/python_files/tests/pytestadapter/expected_discovery_test_output.py @@ -91,7 +91,10 @@ ), } ], - "id_": "unittest_pytest_same_file.py::TestExample", + "id_": get_absolute_test_id( + "unittest_pytest_same_file.py::TestExample", + os.fspath(unit_pytest_same_file_path), + ), }, { "name": "test_true_pytest", @@ -200,7 +203,10 @@ ), }, ], - "id_": "unittest_folder/test_add.py::TestAddFunction", + "id_": get_absolute_test_id( + "unittest_folder/test_add.py::TestAddFunction", + os.fspath(test_add_path), + ), }, { "name": "TestDuplicateFunction", @@ -225,7 +231,10 @@ ), }, ], - "id_": "unittest_folder/test_add.py::TestDuplicateFunction", + "id_": get_absolute_test_id( + "unittest_folder/test_add.py::TestDuplicateFunction", + os.fspath(test_add_path), + ), }, ], }, @@ -275,7 +284,10 @@ ), }, ], - "id_": "unittest_folder/test_subtract.py::TestSubtractFunction", + "id_": get_absolute_test_id( + "unittest_folder/test_subtract.py::TestSubtractFunction", + os.fspath(test_subtract_path), + ), }, { "name": "TestDuplicateFunction", @@ -300,7 +312,10 @@ ), }, ], - "id_": "unittest_folder/test_subtract.py::TestDuplicateFunction", + "id_": get_absolute_test_id( + "unittest_folder/test_subtract.py::TestDuplicateFunction", + test_subtract_path, + ), }, ], }, @@ -534,7 +549,10 @@ "name": "TestClass", "path": os.fspath(parameterize_tests_path), "type_": "class", - "id_": "parametrize_tests.py::TestClass", + "id_": get_absolute_test_id( + "parametrize_tests.py::TestClass", + parameterize_tests_path, + ), "children": [ { "name": "test_adding", @@ -907,13 +925,19 @@ "name": "TestFirstClass", "path": str(TEST_MULTI_CLASS_NEST_PATH), "type_": "class", - "id_": "test_multi_class_nest.py::TestFirstClass", + "id_": get_absolute_test_id( + "test_multi_class_nest.py::TestFirstClass", + TEST_MULTI_CLASS_NEST_PATH, + ), "children": [ { "name": "TestSecondClass", "path": str(TEST_MULTI_CLASS_NEST_PATH), "type_": "class", - "id_": "test_multi_class_nest.py::TestFirstClass::TestSecondClass", + "id_": get_absolute_test_id( + "test_multi_class_nest.py::TestFirstClass::TestSecondClass", + TEST_MULTI_CLASS_NEST_PATH, + ), "children": [ { "name": "test_second", @@ -954,7 +978,10 @@ "name": "TestSecondClass2", "path": str(TEST_MULTI_CLASS_NEST_PATH), "type_": "class", - "id_": "test_multi_class_nest.py::TestFirstClass::TestSecondClass2", + "id_": get_absolute_test_id( + "test_multi_class_nest.py::TestFirstClass::TestSecondClass2", + TEST_MULTI_CLASS_NEST_PATH, + ), "children": [ { "name": "test_second2", @@ -1196,7 +1223,10 @@ + "::TestNotEmpty::test_string", }, ], - "id_": "same_function_new_class_param.py::TestNotEmpty", + "id_": get_absolute_test_id( + "same_function_new_class_param.py::TestNotEmpty", + TEST_DATA_PATH / "same_function_new_class_param.py", + ), }, { "name": "TestEmpty", @@ -1264,7 +1294,10 @@ + "::TestEmpty::test_string", }, ], - "id_": "same_function_new_class_param.py::TestEmpty", + "id_": get_absolute_test_id( + "same_function_new_class_param.py::TestEmpty", + TEST_DATA_PATH / "same_function_new_class_param.py", + ), }, ], } @@ -1334,7 +1367,10 @@ ), } ], - "id_": "test_param_span_class.py::TestClass1", + "id_": get_absolute_test_id( + "test_param_span_class.py::TestClass1", + TEST_DATA_PATH / "test_param_span_class.py", + ), }, { "name": "TestClass2", @@ -1387,7 +1423,10 @@ ), } ], - "id_": "test_param_span_class.py::TestClass2", + "id_": get_absolute_test_id( + "test_param_span_class.py::TestClass2", + TEST_DATA_PATH / "test_param_span_class.py", + ), }, ], } @@ -1460,7 +1499,10 @@ ), }, ], - "id_": "pytest_describe_plugin/describe_only.py::describe_A", + "id_": get_absolute_test_id( + "pytest_describe_plugin/describe_only.py::describe_A", + describe_only_path, + ), } ], } @@ -1540,7 +1582,10 @@ ), }, ], - "id_": "pytest_describe_plugin/nested_describe.py::describe_list::describe_append", + "id_": get_absolute_test_id( + "pytest_describe_plugin/nested_describe.py::describe_list::describe_append", + nested_describe_path, + ), }, { "name": "describe_remove", @@ -1565,10 +1610,16 @@ ), } ], - "id_": "pytest_describe_plugin/nested_describe.py::describe_list::describe_remove", + "id_": get_absolute_test_id( + "pytest_describe_plugin/nested_describe.py::describe_list::describe_remove", + nested_describe_path, + ), }, ], - "id_": "pytest_describe_plugin/nested_describe.py::describe_list", + "id_": get_absolute_test_id( + "pytest_describe_plugin/nested_describe.py::describe_list", + nested_describe_path, + ), } ], } diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index 18469cd0627f..f99c7fa9a758 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -764,12 +764,13 @@ def create_class_node(class_module: pytest.Class | DescribeBlock) -> TestNode: Keyword arguments: class_module -- the pytest object representing a class module. """ + return { "name": class_module.name, "path": get_node_path(class_module), "type_": "class", "children": [], - "id_": class_module.nodeid, + "id_": get_absolute_test_id(class_module.nodeid, get_node_path(class_module)), } From a3267647bc1608f0ba3dab1ccd5e91397a77b264 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Wed, 9 Jul 2025 13:08:32 -0700 Subject: [PATCH 2/2] update to formatting / linting --- .../tests/pytestadapter/expected_discovery_test_output.py | 8 ++++---- python_files/vscode_pytest/__init__.py | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/python_files/tests/pytestadapter/expected_discovery_test_output.py b/python_files/tests/pytestadapter/expected_discovery_test_output.py index 3223970f8315..13bb6ee983cf 100644 --- a/python_files/tests/pytestadapter/expected_discovery_test_output.py +++ b/python_files/tests/pytestadapter/expected_discovery_test_output.py @@ -93,7 +93,7 @@ ], "id_": get_absolute_test_id( "unittest_pytest_same_file.py::TestExample", - os.fspath(unit_pytest_same_file_path), + unit_pytest_same_file_path, ), }, { @@ -205,7 +205,7 @@ ], "id_": get_absolute_test_id( "unittest_folder/test_add.py::TestAddFunction", - os.fspath(test_add_path), + test_add_path, ), }, { @@ -233,7 +233,7 @@ ], "id_": get_absolute_test_id( "unittest_folder/test_add.py::TestDuplicateFunction", - os.fspath(test_add_path), + test_add_path, ), }, ], @@ -286,7 +286,7 @@ ], "id_": get_absolute_test_id( "unittest_folder/test_subtract.py::TestSubtractFunction", - os.fspath(test_subtract_path), + test_subtract_path, ), }, { diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index f99c7fa9a758..de396d8520ef 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -764,7 +764,6 @@ def create_class_node(class_module: pytest.Class | DescribeBlock) -> TestNode: Keyword arguments: class_module -- the pytest object representing a class module. """ - return { "name": class_module.name, "path": get_node_path(class_module),