Skip to content

Commit 9097101

Browse files
andravinclaude
andcommitted
refactor(testing): simplify exclusion filtering in getTestItemsForWorkspace
Remove isTestItemExcluded and exclusion logic from getTestItemsForWorkspace since exclusions are fully handled downstream via expandExcludeSet and getTestCaseNodes in WorkspaceTestAdapter.executeTests. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 02b443c commit 9097101

File tree

3 files changed

+2
-63
lines changed

3 files changed

+2
-63
lines changed

src/client/testing/testController/common/testItemUtilities.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -498,23 +498,6 @@ export async function updateTestItemFromRawData(
498498
item.busy = false;
499499
}
500500

501-
/**
502-
* Checks if a test item or any of its ancestors is in the exclude set.
503-
*/
504-
export function isTestItemExcluded(item: TestItem, excludeSet: Set<TestItem> | undefined): boolean {
505-
if (!excludeSet || excludeSet.size === 0) {
506-
return false;
507-
}
508-
let current: TestItem | undefined = item;
509-
while (current) {
510-
if (excludeSet.has(current)) {
511-
return true;
512-
}
513-
current = current.parent;
514-
}
515-
return false;
516-
}
517-
518501
/**
519502
* Expands an exclude set to include all descendants of excluded items.
520503
* After expansion, checking if a node is excluded is O(1) - just check set membership.

src/client/testing/testController/controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { IEventNamePropertyMapping, sendTelemetryEvent } from '../../telemetry';
3434
import { EventName } from '../../telemetry/constants';
3535
import { PYTEST_PROVIDER, UNITTEST_PROVIDER } from '../common/constants';
3636
import { TestProvider } from '../types';
37-
import { createErrorTestItem, DebugTestTag, getNodeByUri, isTestItemExcluded, RunTestTag } from './common/testItemUtilities';
37+
import { createErrorTestItem, DebugTestTag, getNodeByUri, RunTestTag } from './common/testItemUtilities';
3838
import { buildErrorNodeOptions } from './common/utils';
3939
import { ITestController, ITestFrameworkController, TestRefreshOptions } from './common/types';
4040
import { WorkspaceTestAdapter } from './workspaceTestAdapter';
@@ -848,14 +848,12 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
848848
*/
849849
private getTestItemsForWorkspace(workspace: WorkspaceFolder, request: TestRunRequest): TestItem[] {
850850
const testItems: TestItem[] = [];
851-
const excludeSet = request.exclude?.length ? new Set(request.exclude) : undefined;
852851
// If the run request includes test items then collect only items that belong to
853852
// `workspace`. If there are no items in the run request then just run the `workspace`
854853
// root test node. Include will be `undefined` in the "run all" scenario.
855-
// Exclusions are applied after inclusions per VS Code API contract.
856854
(request.include ?? this.testController.items).forEach((i: TestItem) => {
857855
const w = this.workspaceService.getWorkspaceFolder(i.uri);
858-
if (w?.uri.fsPath === workspace.uri.fsPath && !isTestItemExcluded(i, excludeSet)) {
856+
if (w?.uri.fsPath === workspace.uri.fsPath) {
859857
testItems.push(i);
860858
}
861859
});

src/test/testing/testController/testItemUtilities.unit.test.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as assert from 'assert';
22
import { TestItem } from 'vscode';
33
import {
4-
isTestItemExcluded,
54
expandExcludeSet,
65
getTestCaseNodes,
76
RunTestTag,
@@ -28,47 +27,6 @@ function createMockTestItem(id: string, canResolveChildren: boolean, children: T
2827
return item;
2928
}
3029

31-
suite('isTestItemExcluded', () => {
32-
test('should return false when excludeSet is undefined', () => {
33-
const item = createMockTestItem('item1', false);
34-
assert.strictEqual(isTestItemExcluded(item, undefined), false);
35-
});
36-
37-
test('should return false when excludeSet is empty', () => {
38-
const item = createMockTestItem('item1', false);
39-
assert.strictEqual(isTestItemExcluded(item, new Set()), false);
40-
});
41-
42-
test('should return true when item is directly in excludeSet', () => {
43-
const item = createMockTestItem('item1', false);
44-
const excludeSet = new Set([item]);
45-
assert.strictEqual(isTestItemExcluded(item, excludeSet), true);
46-
});
47-
48-
test('should return true when ancestor is in excludeSet', () => {
49-
const child = createMockTestItem('child', false);
50-
const parent = createMockTestItem('parent', true, [child]);
51-
const excludeSet = new Set([parent]);
52-
assert.strictEqual(isTestItemExcluded(child, excludeSet), true);
53-
});
54-
55-
test('should return false when unrelated item is in excludeSet', () => {
56-
const child = createMockTestItem('child', false);
57-
createMockTestItem('parent', true, [child]);
58-
const other = createMockTestItem('other', false);
59-
const excludeSet = new Set([other]);
60-
assert.strictEqual(isTestItemExcluded(child, excludeSet), false);
61-
});
62-
63-
test('should walk multiple levels of ancestor chain', () => {
64-
const grandchild = createMockTestItem('grandchild', false);
65-
const child = createMockTestItem('child', true, [grandchild]);
66-
const root = createMockTestItem('root', true, [child]);
67-
const excludeSet = new Set([root]);
68-
assert.strictEqual(isTestItemExcluded(grandchild, excludeSet), true);
69-
});
70-
});
71-
7230
suite('expandExcludeSet', () => {
7331
test('should return undefined when excludeSet is undefined', () => {
7432
assert.strictEqual(expandExcludeSet(undefined), undefined);

0 commit comments

Comments
 (0)