Skip to content

Do not trigger test discovery if an invalid interpreter is selected for the workspace #19470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/client/testing/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ export class UnitTestManagementService implements IExtensionActivationService {
if (!wkspace) {
return;
}
const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
const commandManager = this.serviceContainer.get<ICommandManager>(ICommandManager);
if (!(await interpreterService.getActiveInterpreter(wkspace))) {
commandManager.executeCommand('python.triggerEnvSelection', wkspace);
return;
}
const configurationService = this.serviceContainer.get<ITestConfigurationService>(ITestConfigurationService);
await configurationService.promptToEnableAndConfigureTestFramework(wkspace!);
}
Expand Down
38 changes: 33 additions & 5 deletions src/client/testing/testController/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import {
EventEmitter,
} from 'vscode';
import { IExtensionSingleActivationService } from '../../activation/types';
import { IWorkspaceService } from '../../common/application/types';
import { ICommandManager, IWorkspaceService } from '../../common/application/types';
import * as constants from '../../common/constants';
import { IPythonExecutionFactory } from '../../common/process/types';
import { IConfigurationService, IDisposableRegistry, Resource } from '../../common/types';
import { DelayedTrigger, IDelayedTrigger } from '../../common/utils/delayTrigger';
import { traceVerbose } from '../../logging';
import { noop } from '../../common/utils/misc';
import { IInterpreterService } from '../../interpreter/contracts';
import { traceError, traceVerbose } from '../../logging';
import { IEventNamePropertyMapping, sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { PYTEST_PROVIDER, UNITTEST_PROVIDER } from '../common/constants';
Expand Down Expand Up @@ -77,6 +79,8 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
@inject(ITestFrameworkController) @named(UNITTEST_PROVIDER) private readonly unittest: ITestFrameworkController,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
@inject(IPythonExecutionFactory) private readonly pythonExecFactory: IPythonExecutionFactory,
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
@inject(ICommandManager) private readonly commandManager: ICommandManager,
) {
this.refreshCancellation = new CancellationTokenSource();

Expand Down Expand Up @@ -248,7 +252,17 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
} else {
traceVerbose('Testing: Refreshing all test data');
const workspaces: readonly WorkspaceFolder[] = this.workspaceService.workspaceFolders || [];
await Promise.all(workspaces.map((workspace) => this.refreshTestDataInternal(workspace.uri)));
await Promise.all(
workspaces.map(async (workspace) => {
if (!(await this.interpreterService.getActiveInterpreter(workspace.uri))) {
this.commandManager
.executeCommand('python.triggerEnvSelection', workspace.uri)
.then(noop, noop);
return;
}
await this.refreshTestDataInternal(workspace.uri);
}),
);
}
this.refreshingCompletedEvent.fire();
return Promise.resolve();
Expand All @@ -268,7 +282,15 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
traceVerbose('Testing: Refreshing all test data');
this.sendTriggerTelemetry('auto');
const workspaces: readonly WorkspaceFolder[] = this.workspaceService.workspaceFolders || [];
await Promise.all(workspaces.map((workspace) => this.refreshTestDataInternal(workspace.uri)));
await Promise.all(
workspaces.map(async (workspace) => {
if (!(await this.interpreterService.getActiveInterpreter(workspace.uri))) {
traceError('Cannot trigger test discovery as a valid interpreter is not selected');
return;
}
await this.refreshTestDataInternal(workspace.uri);
}),
);
}
return Promise.resolve();
}
Expand Down Expand Up @@ -296,7 +318,13 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
const unconfiguredWorkspaces: WorkspaceFolder[] = [];
try {
await Promise.all(
workspaces.map((workspace) => {
workspaces.map(async (workspace) => {
if (!(await this.interpreterService.getActiveInterpreter(workspace.uri))) {
this.commandManager
.executeCommand('python.triggerEnvSelection', workspace.uri)
.then(noop, noop);
return undefined;
}
const testItems: TestItem[] = [];
// If the run request includes test items then collect only items that belong to
// `workspace`. If there are no items in the run request then just run the `workspace`
Expand Down