Skip to content
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

pytest complicated parameterize test parsing #22001

Merged
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions pythonFiles/tests/pytestadapter/.data/parametrize_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 10 additions & 10 deletions pythonFiles/tests/pytestadapter/expected_discovery_test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
},
Expand Down
4 changes: 4 additions & 0 deletions pythonFiles/tests/pytestadapter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions pythonFiles/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading