Skip to content

Commit

Permalink
Fix for multiple directories in pytest args. (microsoft#17306)
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Sep 8, 2021
1 parent 71bc815 commit 54fef04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/17281.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix for multiple folders in `pytest` args.
25 changes: 17 additions & 8 deletions src/client/testing/testController/pytest/pytestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,30 @@ export class PytestController implements ITestFrameworkController {
item.children.forEach((c) => subRootWithNoData.push(c.id));

rawTestData.forEach((data) => {
let subRootId = data.root;
let rawId;
if (data.root === root) {
const subRoot = data.parents.filter((p) => p.parentid === '.' || p.parentid === root);
subRootId = path.join(data.root, subRoot.length > 0 ? subRoot[0].id : '');
rawId = subRoot.length > 0 ? subRoot[0].id : undefined;
}

if (data.tests.length > 0) {
let subRootItem = item.children.get(data.root);
let subRootItem = item.children.get(subRootId);
if (!subRootItem) {
subRootItem = createWorkspaceRootTestItem(testController, this.idToRawData, {
id: data.root,
label: path.basename(data.root),
uri: Uri.file(data.root),
runId: data.root,
id: subRootId,
label: path.basename(subRootId),
uri: Uri.file(subRootId),
runId: subRootId,
parentId: item.id,
rawId,
});
item.children.add(subRootItem);
}

// We found data for a node. Remove its id for the no-data list.
subRootWithNoData = subRootWithNoData.filter((s) => s !== data.root);
// We found data for a node. Remove its id from the no-data list.
subRootWithNoData = subRootWithNoData.filter((s) => s !== subRootId);
updateTestItemFromRawData(
subRootItem,
testController,
Expand All @@ -111,7 +120,7 @@ export class PytestController implements ITestFrameworkController {
);
} else {
// This means there are no tests under this node
removeItemByIdFromChildren(this.idToRawData, item, [data.root]);
removeItemByIdFromChildren(this.idToRawData, item, [subRootId]);
}
});

Expand Down

0 comments on commit 54fef04

Please sign in to comment.