diff --git a/src/client/testing/testController/controller.ts b/src/client/testing/testController/controller.ts index cd7b516af2b7..5a66b0bb9251 100644 --- a/src/client/testing/testController/controller.ts +++ b/src/client/testing/testController/controller.ts @@ -265,6 +265,7 @@ export class PythonTestController implements ITestController, IExtensionSingleAc // LEGACY MODE: Single WorkspaceTestAdapter per workspace (backward compatibility) workspaces.forEach((workspace) => { this.activateLegacyWorkspace(workspace); + void this.refreshTestData(workspace.uri); }); this.disposables.push( this.workspaceService.onDidChangeWorkspaceFolders((evt) => { diff --git a/src/test/testing/testController/controller.unit.test.ts b/src/test/testing/testController/controller.unit.test.ts index b5a198d0bb46..fa891b84242b 100644 --- a/src/test/testing/testController/controller.unit.test.ts +++ b/src/test/testing/testController/controller.unit.test.ts @@ -92,8 +92,40 @@ suite('PythonTestController', () => { pythonExecFactory, debugLauncher, envVarsService, + + ); } + test('discovers tests for existing workspace during activation', async () => { + const workspaceUri = vscode.Uri.file('/workspace'); + const workspaceFolder = { + uri: workspaceUri, + name: 'workspace', + index: 0, + } as vscode.WorkspaceFolder; + + sandbox.stub(envExtApiInternal, 'useEnvExtension').returns(false); + + const discoveryAdapter = { + discoverTests: sandbox.stub().resolves(undefined), + }; + + sandbox.stub(projectUtils, 'createTestAdapters').returns({ + discoveryAdapter, + executionAdapter: {}, + } as any); + + const controller = createController({ + workspaceService: { + workspaceFolders: [workspaceFolder], + }, + }); + + await controller.activate(); + await new Promise((resolve) => setTimeout(resolve, 350)); + + assert.strictEqual(discoveryAdapter.discoverTests.calledOnce, true); + }); suite('getTestProvider', () => { test('returns unittest when enabled', () => {