diff --git a/src/client/pythonEnvironments/nativeAPI.ts b/src/client/pythonEnvironments/nativeAPI.ts index 31ad80608283..7e2f7aa3515b 100644 --- a/src/client/pythonEnvironments/nativeAPI.ts +++ b/src/client/pythonEnvironments/nativeAPI.ts @@ -384,10 +384,12 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable { const info = toPythonEnvInfo(native); if (info) { const old = this._envs.find((item) => item.executable.filename === info.executable.filename); - if (old && hasChanged(old, info)) { + if (old) { this._envs = this._envs.filter((item) => item.executable.filename !== info.executable.filename); this._envs.push(info); - this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation }); + if (hasChanged(old, info)) { + this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation }); + } } else { this._envs.push(info); this._onChanged.fire({ type: FileChangeType.Created, new: info, searchLocation }); diff --git a/src/test/pythonEnvironments/nativeAPI.unit.test.ts b/src/test/pythonEnvironments/nativeAPI.unit.test.ts index f7f956c7a20e..008d19b4738d 100644 --- a/src/test/pythonEnvironments/nativeAPI.unit.test.ts +++ b/src/test/pythonEnvironments/nativeAPI.unit.test.ts @@ -239,6 +239,27 @@ suite('Native Python API', () => { assert.deepEqual(actual, [expectedConda1]); }); + test('Ensure no duplication on resolve', async () => { + mockFinder + .setup((f) => f.refresh()) + .returns(() => { + async function* generator() { + yield* [conda1]; + } + return generator(); + }) + .verifiable(typemoq.Times.once()); + mockFinder + .setup((f) => f.resolve(typemoq.It.isAny())) + .returns(() => Promise.resolve(conda)) + .verifiable(typemoq.Times.once()); + + await api.triggerRefresh(); + await api.resolveEnv('/home/user/.conda/envs/conda_python/python'); + const actual = api.getEnvs(); + assert.deepEqual(actual, [expectedConda1]); + }); + test('Conda environment with no python', async () => { mockFinder .setup((f) => f.refresh())