diff --git a/src/test/smoke/datascience.smoke.test.ts b/src/test/smoke/datascience.smoke.test.ts index d50a9c2f891..3849359a215 100644 --- a/src/test/smoke/datascience.smoke.test.ts +++ b/src/test/smoke/datascience.smoke.test.ts @@ -26,7 +26,6 @@ suite('Smoke Tests', () => { } api = await initialize(); console.log('api', Object.keys(api)); - provider = api.serviceManager.get(IInteractiveWindowProvider); await setAutoSaveDelayInWorkspaceRoot(1); }); setup(initializeTest); @@ -56,48 +55,6 @@ suite('Smoke Tests', () => { await waitForCondition(checkIfFileHasBeenCreated, timeoutForCellToRun, `"${outputFile}" file not created`); } - test('Interactive window should always pick up current active interpreter', async function () { - // this.timeout(60_000); - // Make an interactive window - await runCellInInteractiveWindow(); - assert.ok(provider?.windows?.length === 1, 'Unexpected number of interactive windows created'); - const currentWindow = provider?.windows[0]; - console.log(currentWindow, currentWindow); - const interpreterForCurrentWindow = currentWindow?.notebook?.getMatchingInterpreter(); - assert.ok(interpreterForCurrentWindow !== undefined, 'Unable to get matching interpreter for current window'); - - // Now change active interpreter - const interpreterService = api.serviceManager.get(IInterpreterService); - const allInterpreters = await interpreterService.getInterpreters(); - assert.ok(allInterpreters.length > 1, 'Not enough interpreters to run interactive window smoke test'); - const differentInterpreter = allInterpreters.find((interpreter) => interpreter !== interpreterForCurrentWindow); - const originalSettingValues: (string | undefined)[] = []; - const settingNames = ['python.defaultInterpreterPath', 'python.pythonPath']; - const configuration = vscode.workspace.getConfiguration(); - for (const setting of settingNames) { - originalSettingValues.push(configuration.get(setting)); - // Save the original setting so we can restore it - await configuration.update(setting, differentInterpreter?.path); - } - await sleep(1_000); // Wait for the Python extension to respond to the setting change - - // Now make another interactive window and confirm it's using the newly selected interpreter - currentWindow.dispose(); - await runCellInInteractiveWindow(); - const newWindow = provider.windows.find((window) => window !== currentWindow); - const interpreterForNewWindow = newWindow?.notebook?.getMatchingInterpreter(); - assert.ok(interpreterForNewWindow !== undefined, 'Unable to get matching interpreter for current window'); - assert.ok( - interpreterForNewWindow === differentInterpreter, - 'Interactive window not created with newly selected interpreter' - ); - - // Restore the settings we changed in the middle of this test - settingNames.forEach(async (setting, i) => { - await configuration.update(setting, originalSettingValues[i]); - }); - }); - test('Random bytes generation', async function () { // We do have a unit test testing this, however create a smoke test to // ensure that the bundling of the native node modules worked @@ -149,4 +106,50 @@ suite('Smoke Tests', () => { // Give time for the file to be saved before we shutdown await sleep(300); }).timeout(timeoutForCellToRun); + + test('Interactive window should always pick up current active interpreter', async function () { + // this.timeout(60_000); + // Make an interactive window + if (!this.api) { + api = await initialize(); + } + provider = api.serviceManager.get(IInteractiveWindowProvider); + await runCellInInteractiveWindow(); + assert.ok(provider?.windows?.length === 1, 'Unexpected number of interactive windows created'); + const currentWindow = provider?.windows[0]; + console.log(currentWindow, currentWindow); + const interpreterForCurrentWindow = currentWindow?.notebook?.getMatchingInterpreter(); + assert.ok(interpreterForCurrentWindow !== undefined, 'Unable to get matching interpreter for current window'); + + // Now change active interpreter + const interpreterService = api.serviceManager.get(IInterpreterService); + const allInterpreters = await interpreterService.getInterpreters(); + assert.ok(allInterpreters.length > 1, 'Not enough interpreters to run interactive window smoke test'); + const differentInterpreter = allInterpreters.find((interpreter) => interpreter !== interpreterForCurrentWindow); + const originalSettingValues: (string | undefined)[] = []; + const settingNames = ['python.defaultInterpreterPath', 'python.pythonPath']; + const configuration = vscode.workspace.getConfiguration(); + for (const setting of settingNames) { + originalSettingValues.push(configuration.get(setting)); + // Save the original setting so we can restore it + await configuration.update(setting, differentInterpreter?.path); + } + await sleep(1_000); // Wait for the Python extension to respond to the setting change + + // Now make another interactive window and confirm it's using the newly selected interpreter + currentWindow.dispose(); + await runCellInInteractiveWindow(); + const newWindow = provider.windows.find((window) => window !== currentWindow); + const interpreterForNewWindow = newWindow?.notebook?.getMatchingInterpreter(); + assert.ok(interpreterForNewWindow !== undefined, 'Unable to get matching interpreter for current window'); + assert.ok( + interpreterForNewWindow === differentInterpreter, + 'Interactive window not created with newly selected interpreter' + ); + + // Restore the settings we changed in the middle of this test + settingNames.forEach(async (setting, i) => { + await configuration.update(setting, originalSettingValues[i]); + }); + }); });