@@ -17,12 +17,14 @@ import {
17
17
EventEmitter ,
18
18
} from 'vscode' ;
19
19
import { IExtensionSingleActivationService } from '../../activation/types' ;
20
- import { IWorkspaceService } from '../../common/application/types' ;
20
+ import { ICommandManager , IWorkspaceService } from '../../common/application/types' ;
21
21
import * as constants from '../../common/constants' ;
22
22
import { IPythonExecutionFactory } from '../../common/process/types' ;
23
23
import { IConfigurationService , IDisposableRegistry , Resource } from '../../common/types' ;
24
24
import { DelayedTrigger , IDelayedTrigger } from '../../common/utils/delayTrigger' ;
25
- import { traceVerbose } from '../../logging' ;
25
+ import { noop } from '../../common/utils/misc' ;
26
+ import { IInterpreterService } from '../../interpreter/contracts' ;
27
+ import { traceError , traceVerbose } from '../../logging' ;
26
28
import { IEventNamePropertyMapping , sendTelemetryEvent } from '../../telemetry' ;
27
29
import { EventName } from '../../telemetry/constants' ;
28
30
import { PYTEST_PROVIDER , UNITTEST_PROVIDER } from '../common/constants' ;
@@ -77,6 +79,8 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
77
79
@inject ( ITestFrameworkController ) @named ( UNITTEST_PROVIDER ) private readonly unittest : ITestFrameworkController ,
78
80
@inject ( IDisposableRegistry ) private readonly disposables : IDisposableRegistry ,
79
81
@inject ( IPythonExecutionFactory ) private readonly pythonExecFactory : IPythonExecutionFactory ,
82
+ @inject ( IInterpreterService ) private readonly interpreterService : IInterpreterService ,
83
+ @inject ( ICommandManager ) private readonly commandManager : ICommandManager ,
80
84
) {
81
85
this . refreshCancellation = new CancellationTokenSource ( ) ;
82
86
@@ -248,7 +252,17 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
248
252
} else {
249
253
traceVerbose ( 'Testing: Refreshing all test data' ) ;
250
254
const workspaces : readonly WorkspaceFolder [ ] = this . workspaceService . workspaceFolders || [ ] ;
251
- await Promise . all ( workspaces . map ( ( workspace ) => this . refreshTestDataInternal ( workspace . uri ) ) ) ;
255
+ await Promise . all (
256
+ workspaces . map ( async ( workspace ) => {
257
+ if ( ! ( await this . interpreterService . getActiveInterpreter ( workspace . uri ) ) ) {
258
+ this . commandManager
259
+ . executeCommand ( 'python.triggerEnvSelection' , workspace . uri )
260
+ . then ( noop , noop ) ;
261
+ return ;
262
+ }
263
+ await this . refreshTestDataInternal ( workspace . uri ) ;
264
+ } ) ,
265
+ ) ;
252
266
}
253
267
this . refreshingCompletedEvent . fire ( ) ;
254
268
return Promise . resolve ( ) ;
@@ -268,7 +282,15 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
268
282
traceVerbose ( 'Testing: Refreshing all test data' ) ;
269
283
this . sendTriggerTelemetry ( 'auto' ) ;
270
284
const workspaces : readonly WorkspaceFolder [ ] = this . workspaceService . workspaceFolders || [ ] ;
271
- await Promise . all ( workspaces . map ( ( workspace ) => this . refreshTestDataInternal ( workspace . uri ) ) ) ;
285
+ await Promise . all (
286
+ workspaces . map ( async ( workspace ) => {
287
+ if ( ! ( await this . interpreterService . getActiveInterpreter ( workspace . uri ) ) ) {
288
+ traceError ( 'Cannot trigger test discovery as a valid interpreter is not selected' ) ;
289
+ return ;
290
+ }
291
+ await this . refreshTestDataInternal ( workspace . uri ) ;
292
+ } ) ,
293
+ ) ;
272
294
}
273
295
return Promise . resolve ( ) ;
274
296
}
@@ -296,7 +318,13 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
296
318
const unconfiguredWorkspaces : WorkspaceFolder [ ] = [ ] ;
297
319
try {
298
320
await Promise . all (
299
- workspaces . map ( ( workspace ) => {
321
+ workspaces . map ( async ( workspace ) => {
322
+ if ( ! ( await this . interpreterService . getActiveInterpreter ( workspace . uri ) ) ) {
323
+ this . commandManager
324
+ . executeCommand ( 'python.triggerEnvSelection' , workspace . uri )
325
+ . then ( noop , noop ) ;
326
+ return undefined ;
327
+ }
300
328
const testItems : TestItem [ ] = [ ] ;
301
329
// If the run request includes test items then collect only items that belong to
302
330
// `workspace`. If there are no items in the run request then just run the `workspace`
0 commit comments