@@ -5,7 +5,7 @@ import { CancellationToken, TestController, Uri, MarkdownString } from 'vscode';
55import * as util from 'util' ;
66import { DiscoveredTestPayload } from './types' ;
77import { TestProvider } from '../../types' ;
8- import { traceError } from '../../../logging' ;
8+ import { traceError , traceWarn } from '../../../logging' ;
99import { Testing } from '../../../common/utils/localize' ;
1010import { createErrorTestItem } from './testItemUtilities' ;
1111import { 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