@@ -499,7 +499,14 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
499499 // Ensure we send test telemetry if it gets disabled again
500500 this . sendTestDisabledTelemetry = true ;
501501
502- // Use project-based discovery if applicable
502+ // Check if any test framework is enabled BEFORE project-based discovery
503+ // This ensures the config screen stays visible when testing is disabled
504+ if ( ! settings . testing . pytestEnabled && ! settings . testing . unittestEnabled ) {
505+ await this . handleNoTestProviderEnabled ( workspace ) ;
506+ return ;
507+ }
508+
509+ // Use project-based discovery if applicable (only reached if testing is enabled)
503510 if ( this . projectRegistry . hasProjects ( workspace . uri ) ) {
504511 await this . discoverAllProjectsInWorkspace ( workspace . uri ) ;
505512 return ;
@@ -510,8 +517,6 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
510517 await this . discoverWorkspaceTestsLegacy ( workspace . uri , 'pytest' ) ;
511518 } else if ( settings . testing . unittestEnabled ) {
512519 await this . discoverWorkspaceTestsLegacy ( workspace . uri , 'unittest' ) ;
513- } else {
514- await this . handleNoTestProviderEnabled ( workspace ) ;
515520 }
516521 }
517522
@@ -521,6 +526,13 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
521526 * This ensures the test tree stays in sync with project changes.
522527 */
523528 private async discoverAllProjectsInWorkspace ( workspaceUri : Uri ) : Promise < void > {
529+ // Defensive check: ensure testing is enabled (should be checked by caller, but be safe)
530+ const settings = this . configSettings . getSettings ( workspaceUri ) ;
531+ if ( ! settings . testing . pytestEnabled && ! settings . testing . unittestEnabled ) {
532+ traceVerbose ( '[test-by-project] Skipping discovery - no test framework enabled' ) ;
533+ return ;
534+ }
535+
524536 // Get existing projects before re-discovery for cleanup
525537 const existingProjects = this . projectRegistry . getProjectsArray ( workspaceUri ) ;
526538
0 commit comments