forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix parameterized test duplicate function different classes (#23439)
fixes #23434 switched parameterized function IDs to now be `path/to/file::ClassIfExists::functionName` so it is an absolute ID and will not be confused across classes.
- Loading branch information
1 parent
a8a0e59
commit b68fa75
Showing
7 changed files
with
285 additions
and
31 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
python_files/tests/pytestadapter/.data/same_function_new_class_param.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import pytest | ||
|
||
|
||
class TestNotEmpty: | ||
@pytest.mark.parametrize("a, b", [(1, 1), (2, 2)]) # test_marker--TestNotEmpty::test_integer | ||
def test_integer(self, a, b): | ||
assert a == b | ||
|
||
@pytest.mark.parametrize( # test_marker--TestNotEmpty::test_string | ||
"a, b", [("a", "a"), ("b", "b")] | ||
) | ||
def test_string(self, a, b): | ||
assert a == b | ||
|
||
|
||
class TestEmpty: | ||
@pytest.mark.parametrize("a, b", [(0, 0)]) # test_marker--TestEmpty::test_integer | ||
def test_integer(self, a, b): | ||
assert a == b | ||
|
||
@pytest.mark.parametrize("a, b", [("", "")]) # test_marker--TestEmpty::test_string | ||
def test_string(self, a, b): | ||
assert a == b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
|
||
def is_same_tree(tree1, tree2) -> bool: | ||
"""Helper function to test if two test trees are the same. | ||
def is_same_tree(tree1, tree2, test_key_arr, path="root") -> bool: | ||
"""Helper function to test if two test trees are the same with detailed error logs. | ||
`is_same_tree` starts by comparing the root attributes, and then checks if all children are the same. | ||
""" | ||
# Compare the root. | ||
if any(tree1[key] != tree2[key] for key in ["path", "name", "type_"]): | ||
return False | ||
for key in ["path", "name", "type_", "id_"]: | ||
if tree1.get(key) != tree2.get(key): | ||
print( | ||
f"Difference found at {path}: '{key}' is '{tree1.get(key)}' in tree1 and '{tree2.get(key)}' in tree2." | ||
) | ||
return False | ||
|
||
# Compare child test nodes if they exist, otherwise compare test items. | ||
if "children" in tree1 and "children" in tree2: | ||
# sort children by path before comparing since order doesn't matter of children | ||
# Sort children by path before comparing since order doesn't matter of children | ||
children1 = sorted(tree1["children"], key=lambda x: x["path"]) | ||
children2 = sorted(tree2["children"], key=lambda x: x["path"]) | ||
|
||
# Compare test nodes. | ||
if len(children1) != len(children2): | ||
print( | ||
f"Difference in number of children at {path}: {len(children1)} in tree1 and {len(children2)} in tree2." | ||
) | ||
return False | ||
else: | ||
return all(is_same_tree(*pair) for pair in zip(children1, children2)) | ||
for i, (child1, child2) in enumerate(zip(children1, children2)): | ||
if not is_same_tree(child1, child2, test_key_arr, path=f"{path} -> child {i}"): | ||
return False | ||
elif "id_" in tree1 and "id_" in tree2: | ||
# Compare test items. | ||
return all(tree1[key] == tree2[key] for key in ["id_", "lineno"]) | ||
for key in test_key_arr: | ||
if tree1.get(key) != tree2.get(key): | ||
print( | ||
f"Difference found at {path}: '{key}' is '{tree1.get(key)}' in tree1 and '{tree2.get(key)}' in tree2." | ||
) | ||
return False | ||
|
||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.