Skip to content

Commit 895fdcb

Browse files
committed
support for unittest on module find err
1 parent 714a747 commit 895fdcb

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,10 @@ export function buildErrorNodeOptions(uri: Uri, message: string, testType: strin
201201
let errorMessage = message;
202202

203203
// Check for missing module errors and provide specific messaging
204-
if (testType === 'pytest') {
205-
const missingModule = extractMissingModuleName(message);
206-
if (missingModule) {
207-
labelText = `Missing Module: ${missingModule}`;
208-
errorMessage = `The module '${missingModule}' is not installed in the selected Python environment. Please install it to enable test discovery.`;
209-
}
204+
const missingModule = extractMissingModuleName(message);
205+
if (missingModule) {
206+
labelText = `Missing Module: ${missingModule}`;
207+
errorMessage = `The module '${missingModule}' is not installed in the selected Python environment. Please install it to enable test discovery.`;
210208
}
211209

212210
return {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,23 @@ suite('buildErrorNodeOptions - missing module detection', () => {
6363
expect(result.error).to.equal('Some other error occurred');
6464
});
6565

66-
test('Should use generic error for unittest errors', () => {
67-
const errorMessage = "ModuleNotFoundError: No module named 'pytest'";
66+
test('Should detect missing module for unittest errors', () => {
67+
const errorMessage = "ModuleNotFoundError: No module named 'pandas'";
68+
69+
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'unittest');
70+
71+
expect(result.label).to.equal('Missing Module: pandas [workspace]');
72+
expect(result.error).to.equal(
73+
"The module 'pandas' is not installed in the selected Python environment. Please install it to enable test discovery.",
74+
);
75+
});
76+
77+
test('Should use generic error for unittest non-module errors', () => {
78+
const errorMessage = 'Some other error occurred';
6879

6980
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'unittest');
7081

7182
expect(result.label).to.equal('Unittest Discovery Error [workspace]');
72-
expect(result.error).to.equal("ModuleNotFoundError: No module named 'pytest'");
83+
expect(result.error).to.equal('Some other error occurred');
7384
});
7485
});

0 commit comments

Comments
 (0)