diff --git a/news/2 Fixes/969.md b/news/2 Fixes/969.md new file mode 100644 index 000000000000..a991de1a919d --- /dev/null +++ b/news/2 Fixes/969.md @@ -0,0 +1 @@ +Ensure conda installer is not used for non-conda environments. diff --git a/src/client/common/installer/condaInstaller.ts b/src/client/common/installer/condaInstaller.ts index a4802817b8d9..10acd9f3bb64 100644 --- a/src/client/common/installer/condaInstaller.ts +++ b/src/client/common/installer/condaInstaller.ts @@ -30,8 +30,8 @@ export class CondaInstaller extends ModuleInstaller implements IModuleInstaller * @returns {Promise} Whether conda is supported as a module installer or not. */ public async isSupported(resource?: Uri): Promise { - if (this.isCondaAvailable !== undefined) { - return this.isCondaAvailable!; + if (this.isCondaAvailable === false) { + return false; } const condaLocator = this.serviceContainer.get(ICondaService); this.isCondaAvailable = await condaLocator.isCondaAvailable(); diff --git a/src/test/common/moduleInstaller.test.ts b/src/test/common/moduleInstaller.test.ts index 768d37afc19f..42e83eb93524 100644 --- a/src/test/common/moduleInstaller.test.ts +++ b/src/test/common/moduleInstaller.test.ts @@ -167,6 +167,22 @@ suite('Module Installer', () => { const condaInstaller = new CondaInstaller(serviceContainer.object); await expect(condaInstaller.isSupported()).to.eventually.equal(true, 'Conda is not supported'); }); + test('Ensure conda is not supported even if conda is available', async () => { + const serviceContainer = TypeMoq.Mock.ofType(); + + const configService = TypeMoq.Mock.ofType(); + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IConfigurationService))).returns(() => configService.object); + const settings = TypeMoq.Mock.ofType(); + const pythonPath = 'pythonABC'; + settings.setup(s => s.pythonPath).returns(() => pythonPath); + configService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object); + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(ICondaService))).returns(() => condaService.object); + condaService.setup(c => c.isCondaAvailable()).returns(() => Promise.resolve(true)); + condaService.setup(c => c.isCondaEnvironment(TypeMoq.It.isValue(pythonPath))).returns(() => Promise.resolve(false)); + + const condaInstaller = new CondaInstaller(serviceContainer.object); + await expect(condaInstaller.isSupported()).to.eventually.equal(false, 'Conda should not be supported'); + }); test('Validate pip install arguments', async () => { const interpreterPath = await getCurrentPythonPath();