Skip to content

Commit efea57e

Browse files
committed
updates
1 parent 75b0e02 commit efea57e

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

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';
@@ -92,6 +92,28 @@ export class TestDiscoveryHandler {
9292

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

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

0 commit comments

Comments
 (0)