Skip to content

Commit e6b6cc2

Browse files
committed
updates
1 parent f53a64a commit e6b6cc2

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/client/testing/common/debugLauncher.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class DebugLauncher implements ITestDebugLauncher {
177177
include: false,
178178
});
179179

180-
DebugLauncher.applyDefaults(debugConfig!, workspaceFolder, configSettings);
180+
DebugLauncher.applyDefaults(debugConfig!, workspaceFolder, configSettings, options.cwd);
181181

182182
return this.convertConfigToArgs(debugConfig!, workspaceFolder, options);
183183
}
@@ -224,14 +224,17 @@ export class DebugLauncher implements ITestDebugLauncher {
224224
cfg: LaunchRequestArguments,
225225
workspaceFolder: WorkspaceFolder,
226226
configSettings: IPythonSettings,
227+
optionsCwd?: string,
227228
) {
228229
// cfg.pythonPath is handled by LaunchConfigurationResolver.
229230

230231
if (!cfg.console) {
231232
cfg.console = 'internalConsole';
232233
}
233234
if (!cfg.cwd) {
234-
cfg.cwd = configSettings.testing.cwd || workspaceFolder.uri.fsPath;
235+
// For project-based testing, use the project's cwd (optionsCwd) if provided.
236+
// Otherwise fall back to settings.testing.cwd or the workspace folder.
237+
cfg.cwd = optionsCwd || configSettings.testing.cwd || workspaceFolder.uri.fsPath;
235238
}
236239
if (!cfg.env) {
237240
cfg.env = {};

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CancellationToken, TestController, Uri, MarkdownString } from 'vscode';
55
import * as util from 'util';
66
import { DiscoveredTestPayload } from './types';
77
import { TestProvider } from '../../types';
8-
import { traceError } from '../../../logging';
8+
import { traceError, traceWarn } from '../../../logging';
99
import { Testing } from '../../../common/utils/localize';
1010
import { createErrorTestItem } from './testItemUtilities';
1111
import { buildErrorNodeOptions, populateTestTree } from './utils';
@@ -93,6 +93,28 @@ export class TestDiscoveryHandler {
9393

9494
traceError(testingErrorConst, 'for workspace: ', workspacePath, '\r\n', error?.join('\r\n\r\n') ?? '');
9595

96+
// For unittest in project-based mode, check if the error might be caused by nested project imports
97+
// This helps users understand that import errors from nested projects can be safely ignored
98+
// if those tests are covered by a different project with the correct environment.
99+
if (testProvider === 'unittest' && projectId) {
100+
const errorText = error?.join(' ') ?? '';
101+
const isImportError =
102+
errorText.includes('ModuleNotFoundError') ||
103+
errorText.includes('ImportError') ||
104+
errorText.includes('No module named');
105+
106+
if (isImportError) {
107+
traceWarn(
108+
`---
109+
[test-by-project] Import error during unittest discovery for project at ${workspacePath}. ` +
110+
`This may be caused by test files in nested project directories that require different dependencies. ` +
111+
`If these tests are discovered successfully by their own project (with the correct Python environment), ` +
112+
`this error can be safely ignored. To avoid this, consider excluding nested project paths from parent project discovery.
113+
---`,
114+
);
115+
}
116+
}
117+
96118
const errorNodeId = projectId
97119
? `${projectId}${PROJECT_ID_SEPARATOR}DiscoveryError:${workspacePath}`
98120
: `DiscoveryError:${workspacePath}`;

0 commit comments

Comments
 (0)