Skip to content

Commit 18208e0

Browse files
authored
Merge branch 'test-project-support' into instant-eagle-pytest-execution
2 parents a0c557d + 42fb7b7 commit 18208e0

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class TestDiscoveryHandler {
4141

4242
// Check if there were any errors in the discovery process.
4343
if (rawTestData.status === 'error') {
44-
this.createErrorNode(testController, workspaceUri, rawTestData.error, testProvider, projectId);
44+
this.createErrorNode(testController, workspaceUri, rawTestData.error, testProvider, projectId, projectName);
4545
} else {
4646
// remove error node only if no errors exist.
4747
const errorNodeId = projectId
@@ -85,6 +85,7 @@ export class TestDiscoveryHandler {
8585
error: string[] | undefined,
8686
testProvider: TestProvider,
8787
projectId?: string,
88+
projectName?: string,
8889
): void {
8990
const workspacePath = workspaceUri.fsPath;
9091
const testingErrorConst =
@@ -102,7 +103,7 @@ export class TestDiscoveryHandler {
102103
);
103104

104105
if (errorNode === undefined) {
105-
const options = buildErrorNodeOptions(workspaceUri, message, testProvider);
106+
const options = buildErrorNodeOptions(workspaceUri, message, testProvider, projectName);
106107
// Update the error node ID to include project scope if applicable
107108
options.id = errorNodeId;
108109
errorNode = createErrorTestItem(testController, options);

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ function isPytestNotInstalledError(message: string): boolean {
188188
);
189189
}
190190

191-
export function buildErrorNodeOptions(uri: Uri, message: string, testType: string): ErrorTestItemOptions {
191+
export function buildErrorNodeOptions(
192+
uri: Uri,
193+
message: string,
194+
testType: string,
195+
projectName?: string,
196+
): ErrorTestItemOptions {
192197
let labelText = testType === 'pytest' ? 'pytest Discovery Error' : 'Unittest Discovery Error';
193198
let errorMessage = message;
194199

@@ -199,9 +204,12 @@ export function buildErrorNodeOptions(uri: Uri, message: string, testType: strin
199204
'pytest is not installed in the selected Python environment. Please install pytest to enable test discovery and execution.';
200205
}
201206

207+
// Use project name for label if available (project-based testing), otherwise use folder name
208+
const displayName = projectName ?? path.basename(uri.fsPath);
209+
202210
return {
203211
id: `DiscoveryError:${uri.fsPath}`,
204-
label: `${labelText} [${path.basename(uri.fsPath)}]`,
212+
label: `${labelText} [${displayName}]`,
205213
error: errorMessage,
206214
};
207215
}

src/test/testing/testController/common/buildErrorNodeOptions.unit.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,30 @@ suite('buildErrorNodeOptions - pytest not installed detection', () => {
4848
expect(result.label).to.equal('Unittest Discovery Error [workspace]');
4949
expect(result.error).to.equal("ModuleNotFoundError: No module named 'pytest'");
5050
});
51+
52+
test('Should use project name in label when projectName is provided', () => {
53+
const errorMessage = 'Some error occurred';
54+
55+
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'unittest', 'my-project');
56+
57+
expect(result.label).to.equal('Unittest Discovery Error [my-project]');
58+
expect(result.error).to.equal('Some error occurred');
59+
});
60+
61+
test('Should use project name in label for pytest when projectName is provided', () => {
62+
const errorMessage = 'Some error occurred';
63+
64+
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'pytest', 'ada');
65+
66+
expect(result.label).to.equal('pytest Discovery Error [ada]');
67+
expect(result.error).to.equal('Some error occurred');
68+
});
69+
70+
test('Should use folder name when projectName is undefined', () => {
71+
const errorMessage = 'Some error occurred';
72+
73+
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'unittest', undefined);
74+
75+
expect(result.label).to.equal('Unittest Discovery Error [workspace]');
76+
});
5177
});

0 commit comments

Comments
 (0)