diff --git a/src/client/application/diagnostics/checks/pythonInterpreter.ts b/src/client/application/diagnostics/checks/pythonInterpreter.ts index 7f85e28095dd..87ba83cbbc66 100644 --- a/src/client/application/diagnostics/checks/pythonInterpreter.ts +++ b/src/client/application/diagnostics/checks/pythonInterpreter.ts @@ -7,7 +7,7 @@ import { DiagnosticSeverity } from 'vscode'; import '../../../common/extensions'; import * as nls from 'vscode-nls'; import * as path from 'path'; -import { IDisposableRegistry, Resource } from '../../../common/types'; +import { IDisposableRegistry, IInterpreterPathService, Resource } from '../../../common/types'; import { IInterpreterService } from '../../../interpreter/contracts'; import { IServiceContainer } from '../../../ioc/types'; import { BaseDiagnostic, BaseDiagnosticsService } from '../base'; @@ -109,8 +109,10 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService const workspaceService = this.serviceContainer.get(IWorkspaceService); const interpreterService = this.serviceContainer.get(IInterpreterService); const hasInterpreters = await interpreterService.hasInterpreters(); + const interpreterPathService = this.serviceContainer.get(IInterpreterPathService); + const isInterpreterSetToDefault = interpreterPathService.get(resource) === 'python'; - if (!hasInterpreters) { + if (!hasInterpreters && isInterpreterSetToDefault) { return [ new InvalidPythonInterpreterDiagnostic( DiagnosticCodes.NoPythonInterpretersDiagnostic, diff --git a/src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts b/src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts index 78e463482668..bbca6c1a84e4 100644 --- a/src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts +++ b/src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts @@ -28,7 +28,7 @@ import { CommandsWithoutArgs } from '../../../../client/common/application/comma import { ICommandManager, IWorkspaceService } from '../../../../client/common/application/types'; import { Commands } from '../../../../client/common/constants'; import { IPlatformService } from '../../../../client/common/platform/types'; -import { IDisposable, IDisposableRegistry, Resource } from '../../../../client/common/types'; +import { IDisposable, IDisposableRegistry, IInterpreterPathService, Resource } from '../../../../client/common/types'; import { Common } from '../../../../client/common/utils/localize'; import { noop } from '../../../../client/common/utils/misc'; import { IInterpreterHelper, IInterpreterService } from '../../../../client/interpreter/contracts'; @@ -46,6 +46,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { let commandManager: typemoq.IMock; let helper: typemoq.IMock; let serviceContainer: typemoq.IMock; + let interpreterPathService: typemoq.IMock; function createContainer() { serviceContainer = typemoq.Mock.ofType(); workspaceService = typemoq.Mock.ofType(); @@ -76,6 +77,11 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { serviceContainer .setup((s) => s.get(typemoq.It.isValue(IPlatformService))) .returns(() => platformService.object); + interpreterPathService = typemoq.Mock.ofType(); + interpreterPathService.setup((i) => i.get(typemoq.It.isAny())).returns(() => 'customPython'); + serviceContainer + .setup((s) => s.get(typemoq.It.isValue(IInterpreterPathService))) + .returns(() => interpreterPathService.object); helper = typemoq.Mock.ofType(); serviceContainer.setup((s) => s.get(typemoq.It.isValue(IInterpreterHelper))).returns(() => helper.object); serviceContainer.setup((s) => s.get(typemoq.It.isValue(IDisposableRegistry))).returns(() => []); @@ -160,7 +166,9 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { expect(diagnostics).to.be.deep.equal([], 'not the same'); }); - test('Should return diagnostics if there are no interpreters after double-checking', async () => { + test('Should return diagnostics if there are no interpreters and no interpreter has been explicitly set', async () => { + interpreterPathService.reset(); + interpreterPathService.setup((i) => i.get(typemoq.It.isAny())).returns(() => 'python'); interpreterService .setup((i) => i.hasInterpreters()) .returns(() => Promise.resolve(false))