@@ -241,39 +241,46 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
241
241
if ( uri ) {
242
242
const settings = this . configSettings . getSettings ( uri ) ;
243
243
traceVerbose ( `Testing: Refreshing test data for ${ uri . fsPath } ` ) ;
244
+ const rewriteTestingEnabled = process . env . ENABLE_PYTHON_TESTING_REWRITE ;
244
245
if ( settings . testing . pytestEnabled ) {
245
246
// Ensure we send test telemetry if it gets disabled again
246
247
this . sendTestDisabledTelemetry = true ;
247
- // ** uncomment ~231 - 241 to NEW new test discovery mechanism
248
- // const workspace = this.workspaceService.getWorkspaceFolder(uri);
249
- // traceVerbose(`Discover tests for workspace name: ${workspace?.name} - uri: ${uri.fsPath}`);
250
- // const testAdapter =
251
- // this.testAdapters.get(uri) || (this.testAdapters.values().next().value as WorkspaceTestAdapter);
252
- // testAdapter.discoverTests(
253
- // this.testController,
254
- // this.refreshCancellation.token,
255
- // this.testAdapters.size > 1,
256
- // this.workspaceService.workspaceFile?.fsPath,
257
- // this.pythonExecFactory,
258
- // );
259
- // uncomment ~243 to use OLD test discovery mechanism
260
- await this . pytest . refreshTestData ( this . testController , uri , this . refreshCancellation . token ) ;
248
+ if ( rewriteTestingEnabled ) {
249
+ // ** rewriteTestingEnabled set to true to use NEW test discovery mechanism
250
+ const workspace = this . workspaceService . getWorkspaceFolder ( uri ) ;
251
+ traceVerbose ( `Discover tests for workspace name: ${ workspace ?. name } - uri: ${ uri . fsPath } ` ) ;
252
+ const testAdapter =
253
+ this . testAdapters . get ( uri ) || ( this . testAdapters . values ( ) . next ( ) . value as WorkspaceTestAdapter ) ;
254
+ testAdapter . discoverTests (
255
+ this . testController ,
256
+ this . refreshCancellation . token ,
257
+ this . testAdapters . size > 1 ,
258
+ this . workspaceService . workspaceFile ?. fsPath ,
259
+ this . pythonExecFactory ,
260
+ ) ;
261
+ } else {
262
+ // else use OLD test discovery mechanism
263
+ await this . pytest . refreshTestData ( this . testController , uri , this . refreshCancellation . token ) ;
264
+ }
261
265
} else if ( settings . testing . unittestEnabled ) {
262
266
// ** Ensure we send test telemetry if it gets disabled again
263
267
this . sendTestDisabledTelemetry = true ;
264
- // uncomment ~248 - 258 to NEW new test discovery mechanism
265
- // const workspace = this.workspaceService.getWorkspaceFolder(uri);
266
- // traceVerbose(`Discover tests for workspace name: ${workspace?.name} - uri: ${uri.fsPath}`);
267
- // const testAdapter =
268
- // this.testAdapters.get(uri) || (this.testAdapters.values().next().value as WorkspaceTestAdapter);
269
- // testAdapter.discoverTests(
270
- // this.testController,
271
- // this.refreshCancellation.token,
272
- // this.testAdapters.size > 1,
273
- // this.workspaceService.workspaceFile?.fsPath,
274
- // );
275
- // uncomment ~260 to use OLD test discovery mechanism
276
- await this . unittest . refreshTestData ( this . testController , uri , this . refreshCancellation . token ) ;
268
+ if ( rewriteTestingEnabled ) {
269
+ // ** rewriteTestingEnabled set to true to use NEW test discovery mechanism
270
+ const workspace = this . workspaceService . getWorkspaceFolder ( uri ) ;
271
+ traceVerbose ( `Discover tests for workspace name: ${ workspace ?. name } - uri: ${ uri . fsPath } ` ) ;
272
+ const testAdapter =
273
+ this . testAdapters . get ( uri ) || ( this . testAdapters . values ( ) . next ( ) . value as WorkspaceTestAdapter ) ;
274
+ testAdapter . discoverTests (
275
+ this . testController ,
276
+ this . refreshCancellation . token ,
277
+ this . testAdapters . size > 1 ,
278
+ this . workspaceService . workspaceFile ?. fsPath ,
279
+ ) ;
280
+ } else {
281
+ // else use OLD test discovery mechanism
282
+ await this . unittest . refreshTestData ( this . testController , uri , this . refreshCancellation . token ) ;
283
+ }
277
284
} else {
278
285
if ( this . sendTestDisabledTelemetry ) {
279
286
this . sendTestDisabledTelemetry = false ;
@@ -384,25 +391,26 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
384
391
385
392
const settings = this . configSettings . getSettings ( workspace . uri ) ;
386
393
if ( testItems . length > 0 ) {
394
+ const rewriteTestingEnabled = process . env . ENABLE_PYTHON_TESTING_REWRITE ;
387
395
if ( settings . testing . pytestEnabled ) {
388
396
sendTelemetryEvent ( EventName . UNITTEST_RUN , undefined , {
389
397
tool : 'pytest' ,
390
398
debugging : request . profile ?. kind === TestRunProfileKind . Debug ,
391
399
} ) ;
392
- // ** new execution runner/adapter
393
- // const testAdapter =
394
- // this.testAdapters.get(workspace.uri) ||
395
- // ( this.testAdapters.values().next().value as WorkspaceTestAdapter);
396
- // return testAdapter.executeTests(
397
- // this.testController,
398
- // runInstance ,
399
- // testItems ,
400
- // token ,
401
- // request.profile?.kind === TestRunProfileKind.Debug ,
402
- // this.pythonExecFactory ,
403
- // );
404
-
405
- // below is old way of running pytest execution
400
+ // ** rewriteTestingEnabled set to true to use NEW test discovery mechanism
401
+ if ( rewriteTestingEnabled ) {
402
+ const testAdapter =
403
+ this . testAdapters . get ( workspace . uri ) ||
404
+ ( this . testAdapters . values ( ) . next ( ) . value as WorkspaceTestAdapter ) ;
405
+ return testAdapter . executeTests (
406
+ this . testController ,
407
+ runInstance ,
408
+ testItems ,
409
+ token ,
410
+ request . profile ?. kind === TestRunProfileKind . Debug ,
411
+ this . pythonExecFactory ,
412
+ ) ;
413
+ }
406
414
return this . pytest . runTests (
407
415
{
408
416
includes : testItems ,
@@ -415,23 +423,23 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
415
423
) ;
416
424
}
417
425
if ( settings . testing . unittestEnabled ) {
418
- // potentially squeeze in the new execution way here?
419
426
sendTelemetryEvent ( EventName . UNITTEST_RUN , undefined , {
420
427
tool : 'unittest' ,
421
428
debugging : request . profile ?. kind === TestRunProfileKind . Debug ,
422
429
} ) ;
423
- // new execution runner/adapter
424
- // const testAdapter =
425
- // this.testAdapters.get(workspace.uri) ||
426
- // (this.testAdapters.values().next().value as WorkspaceTestAdapter);
427
- // return testAdapter.executeTests(
428
- // this.testController,
429
- // runInstance,
430
- // testItems,
431
- // token,
432
- // request.profile?.kind === TestRunProfileKind.Debug,
433
- // );
434
-
430
+ // ** rewriteTestingEnabled set to true to use NEW test discovery mechanism
431
+ if ( rewriteTestingEnabled ) {
432
+ const testAdapter =
433
+ this . testAdapters . get ( workspace . uri ) ||
434
+ ( this . testAdapters . values ( ) . next ( ) . value as WorkspaceTestAdapter ) ;
435
+ return testAdapter . executeTests (
436
+ this . testController ,
437
+ runInstance ,
438
+ testItems ,
439
+ token ,
440
+ request . profile ?. kind === TestRunProfileKind . Debug ,
441
+ ) ;
442
+ }
435
443
// below is old way of running unittest execution
436
444
return this . unittest . runTests (
437
445
{
0 commit comments