Skip to content

Commit 63117fc

Browse files
author
Kartik Raj
authored
Use correct python executable when running code using Python execution factory (#17614)
1 parent 01c75f1 commit 63117fc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/client/common/process/pythonExecutionFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
8282
);
8383
}
8484
}
85+
pythonPath = this.configService.getSettings(options.resource).pythonPath;
8586
}
86-
pythonPath = this.configService.getSettings(options.resource).pythonPath;
8787
const processService: IProcessService = await this.processServiceFactory.create(options.resource);
8888
processService.on('exec', this.logger.logProcess.bind(this.logger));
8989

src/test/common/process/pythonExecutionFactory.unit.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,23 @@ suite('Process - PythonExecutionFactory', () => {
188188
verify(pythonSettings.pythonPath).once();
189189
});
190190

191+
test('If interpreter is explicitly set, ensure we use it', async () => {
192+
const pythonSettings = mock(PythonSettings);
193+
when(processFactory.create(resource)).thenResolve(processService.object);
194+
inDiscoveryExperimentStub.resolves(true);
195+
when(activationHelper.getActivatedEnvironmentVariables(resource)).thenResolve({ x: '1' });
196+
reset(interpreterPathExpHelper);
197+
when(interpreterPathExpHelper.get(anything())).thenReturn('python');
198+
when(autoSelection.autoSelectInterpreter(anything())).thenResolve();
199+
when(configService.getSettings(resource)).thenReturn(instance(pythonSettings));
200+
201+
const service = await factory.create({ resource, pythonPath: 'HELLO' });
202+
203+
expect(service).to.not.equal(undefined);
204+
verify(pyenvs.isWindowsStoreInterpreter('HELLO')).once();
205+
verify(pythonSettings.pythonPath).never();
206+
});
207+
191208
test('If no interpreter is explicitly set, ensure we autoselect before PythonExecutionService is created', async () => {
192209
const pythonSettings = mock(PythonSettings);
193210
when(processFactory.create(resource)).thenResolve(processService.object);

0 commit comments

Comments
 (0)