Skip to content

Commit

Permalink
use abspath for top_level_dir for build_test_tree (#22740)
Browse files Browse the repository at this point in the history
fixes #22727
  • Loading branch information
eleanorjboyd authored Jan 11, 2024
1 parent 127457d commit 63cf263
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pythonFiles/tests/unittestadapter/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,71 @@ def test_simple_discovery() -> None:
assert "error" not in actual


def test_simple_discovery_with_top_dir_calculated() -> None:
"""The discover_tests function should return a dictionary with a "success" status, a uuid, no errors, and a test tree
if unittest discovery was performed successfully.
"""
start_dir = "."
pattern = "discovery_simple*"
file_path = os.fsdecode(pathlib.PurePath(TEST_DATA_PATH / "discovery_simple.py"))

expected = {
"path": os.fsdecode(pathlib.PurePath(TEST_DATA_PATH)),
"type_": TestNodeTypeEnum.folder,
"name": ".data",
"children": [
{
"name": "discovery_simple.py",
"type_": TestNodeTypeEnum.file,
"path": file_path,
"children": [
{
"name": "DiscoverySimple",
"path": file_path,
"type_": TestNodeTypeEnum.class_,
"children": [
{
"name": "test_one",
"path": file_path,
"type_": TestNodeTypeEnum.test,
"lineno": "14",
"id_": file_path
+ "\\"
+ "DiscoverySimple"
+ "\\"
+ "test_one",
},
{
"name": "test_two",
"path": file_path,
"type_": TestNodeTypeEnum.test,
"lineno": "17",
"id_": file_path
+ "\\"
+ "DiscoverySimple"
+ "\\"
+ "test_two",
},
],
"id_": file_path + "\\" + "DiscoverySimple",
}
],
"id_": file_path,
}
],
"id_": os.fsdecode(pathlib.PurePath(TEST_DATA_PATH)),
}

uuid = "some-uuid"
# Define the CWD to be the root of the test data folder.
os.chdir(os.fsdecode(pathlib.PurePath(TEST_DATA_PATH)))
actual = discover_tests(start_dir, pattern, None, uuid)

assert actual["status"] == "success"
assert is_same_tree(actual.get("tests"), expected)
assert "error" not in actual


def test_empty_discovery() -> None:
"""The discover_tests function should return a dictionary with a "success" status, a uuid, no errors, and no test tree
if unittest discovery was performed successfully but no tests were found.
Expand Down
3 changes: 3 additions & 0 deletions pythonFiles/unittestadapter/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def discover_tests(
if top_level_dir is None:
top_level_dir = start_dir

# Get abspath of top level directory for build_test_tree.
top_level_dir = os.path.abspath(top_level_dir)

tests, error = build_test_tree(
suite, top_level_dir
) # test tree built successfully here.
Expand Down

0 comments on commit 63cf263

Please sign in to comment.