diff --git a/pythonFiles/tests/pytestadapter/.data/parametrize_tests.py b/pythonFiles/tests/pytestadapter/.data/parametrize_tests.py index a39b7c26de9f..c4dbadc32d6e 100644 --- a/pythonFiles/tests/pytestadapter/.data/parametrize_tests.py +++ b/pythonFiles/tests/pytestadapter/.data/parametrize_tests.py @@ -15,6 +15,8 @@ def test_adding(actual, expected): # Testing pytest with parametrized tests. All three pass. # The tests ids are parametrize_tests.py::test_under_ten[1] and so on. -@pytest.mark.parametrize("num", range(1, 3)) # test_marker--test_under_ten -def test_under_ten(num): - assert num < 10 +@pytest.mark.parametrize( # test_marker--test_string + "string", ["hello", "complicated split [] ()"] +) +def test_string(string): + assert string == "hello" diff --git a/pythonFiles/tests/pytestadapter/expected_discovery_test_output.py b/pythonFiles/tests/pytestadapter/expected_discovery_test_output.py index 2b2c07ab8ea7..31686d2b3b5d 100644 --- a/pythonFiles/tests/pytestadapter/expected_discovery_test_output.py +++ b/pythonFiles/tests/pytestadapter/expected_discovery_test_output.py @@ -594,46 +594,46 @@ ], }, { - "name": "test_under_ten", + "name": "test_string", "path": os.fspath(parameterize_tests_path), "type_": "function", "children": [ { - "name": "[1]", + "name": "[hello]", "path": os.fspath(parameterize_tests_path), "lineno": find_test_line_number( - "test_under_ten[1]", + "test_string[hello]", parameterize_tests_path, ), "type_": "test", "id_": get_absolute_test_id( - "parametrize_tests.py::test_under_ten[1]", + "parametrize_tests.py::test_string[hello]", parameterize_tests_path, ), "runID": get_absolute_test_id( - "parametrize_tests.py::test_under_ten[1]", + "parametrize_tests.py::test_string[hello]", parameterize_tests_path, ), }, { - "name": "[2]", + "name": "[complicated split [] ()]", "path": os.fspath(parameterize_tests_path), "lineno": find_test_line_number( - "test_under_ten[2]", + "test_string[1]", parameterize_tests_path, ), "type_": "test", "id_": get_absolute_test_id( - "parametrize_tests.py::test_under_ten[2]", + "parametrize_tests.py::test_string[complicated split [] ()]", parameterize_tests_path, ), "runID": get_absolute_test_id( - "parametrize_tests.py::test_under_ten[2]", + "parametrize_tests.py::test_string[complicated split [] ()]", parameterize_tests_path, ), }, ], - "id_": "parametrize_tests.py::test_under_ten", + "id_": "parametrize_tests.py::test_string", }, ], }, diff --git a/pythonFiles/tests/pytestadapter/helpers.py b/pythonFiles/tests/pytestadapter/helpers.py index 7195cfe43ea5..b534e950945a 100644 --- a/pythonFiles/tests/pytestadapter/helpers.py +++ b/pythonFiles/tests/pytestadapter/helpers.py @@ -12,6 +12,10 @@ import uuid from typing import Any, Dict, List, Optional, Tuple +script_dir = pathlib.Path(__file__).parent.parent.parent +sys.path.append(os.fspath(script_dir)) +sys.path.append(os.fspath(script_dir / "lib" / "python")) + TEST_DATA_PATH = pathlib.Path(__file__).parent / ".data" from typing_extensions import TypedDict diff --git a/pythonFiles/vscode_pytest/__init__.py b/pythonFiles/vscode_pytest/__init__.py index 3d5bde44204f..9e315d7919bb 100644 --- a/pythonFiles/vscode_pytest/__init__.py +++ b/pythonFiles/vscode_pytest/__init__.py @@ -392,9 +392,9 @@ def build_test_tree(session: pytest.Session) -> TestNode: elif hasattr(test_case, "callspec"): # This means it is a parameterized test. function_name: str = "" # parameterized test cases cut the repetitive part of the name off. - name_split = test_node["name"].split("[") - test_node["name"] = "[" + name_split[1] - parent_path = os.fspath(get_node_path(test_case)) + "::" + name_split[0] + parent_part, parameterized_section = test_node["name"].split("[", 1) + test_node["name"] = "[" + parameterized_section + parent_path = os.fspath(get_node_path(test_case)) + "::" + parent_part try: function_name = test_case.originalname # type: ignore function_test_case = function_nodes_dict[parent_path]