Skip to content

Commit b1931a3

Browse files
authored
fix bug which merges all parametrize test classes (#21542)
fixes #21541
1 parent 2674842 commit b1931a3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

pythonFiles/tests/pytestadapter/.data/parametrize_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@
88
)
99
def test_adding(actual, expected):
1010
assert eval(actual) == expected
11+
12+
13+
# Testing pytest with parametrized tests. All three pass.
14+
# The tests ids are parametrize_tests.py::test_under_ten[1] and so on.
15+
@pytest.mark.parametrize("num", range(1, 3)) # test_marker--test_under_ten
16+
def test_under_ten(num):
17+
assert num < 10

pythonFiles/tests/pytestadapter/expected_discovery_test_output.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,30 @@
438438
},
439439
],
440440
},
441+
{
442+
"name": "test_under_ten",
443+
"path": parameterize_tests_path,
444+
"type_": "function",
445+
"children": [
446+
{
447+
"name": "[1]",
448+
"path": parameterize_tests_path,
449+
"lineno": "15",
450+
"type_": "test",
451+
"id_": "parametrize_tests.py::test_under_ten[1]",
452+
"runID": "parametrize_tests.py::test_under_ten[1]",
453+
},
454+
{
455+
"name": "[2]",
456+
"path": parameterize_tests_path,
457+
"lineno": "15",
458+
"type_": "test",
459+
"id_": "parametrize_tests.py::test_under_ten[2]",
460+
"runID": "parametrize_tests.py::test_under_ten[2]",
461+
},
462+
],
463+
"id_": "parametrize_tests.py::test_under_ten",
464+
},
441465
],
442466
},
443467
],

pythonFiles/vscode_pytest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def build_test_tree(session: pytest.Session) -> TestNode:
290290
# parameterized test cases cut the repetitive part of the name off.
291291
name_split = test_node["name"].split("[")
292292
test_node["name"] = "[" + name_split[1]
293-
parent_path = os.fspath(test_case.path)
293+
parent_path = os.fspath(test_case.path) + "::" + name_split[0]
294294
try:
295295
function_name = test_case.originalname # type: ignore
296296
function_test_case = function_nodes_dict[parent_path]

0 commit comments

Comments
 (0)