diff --git a/src/client/testing/testController/common/resultResolver.ts b/src/client/testing/testController/common/resultResolver.ts index fd927262348d..aa9f2a541f51 100644 --- a/src/client/testing/testController/common/resultResolver.ts +++ b/src/client/testing/testController/common/resultResolver.ts @@ -216,9 +216,11 @@ export class PythonResultResolver implements ITestResultResolver { throw new Error('Parent test item not found'); } } else if (rawTestExecData.result[keyTemp].outcome === 'subtest-success') { - // split on " " since the subtest ID has the parent test ID in the first part of the ID. - const parentTestCaseId = keyTemp.split(' [')[0]; - const subtestId = `[${keyTemp.split(' [')[1]}`; + // split only on first " [" since the subtest ID has the parent test ID in the first part of the ID. + const index = keyTemp.indexOf(' ['); + const parentTestCaseId = keyTemp.substring(0, index); + // add one to index to remove the space from the start of the subtest ID + const subtestId = keyTemp.substring(index + 1, keyTemp.length); const parentTestItem = this.runIdToTestItem.get(parentTestCaseId); // find the subtest's parent test item diff --git a/src/test/testing/testController/resultResolver.unit.test.ts b/src/test/testing/testController/resultResolver.unit.test.ts index eff985c7e5e8..694fdacb8049 100644 --- a/src/test/testing/testController/resultResolver.unit.test.ts +++ b/src/test/testing/testController/resultResolver.unit.test.ts @@ -270,15 +270,16 @@ suite('Result Resolver tests', () => { testProvider, workspaceUri, ); - const mockSubtestItem = createMockTestItem('parentTest [subTest with spaces]'); + const subtestName = 'parentTest [subTest with spaces and [brackets]]'; + const mockSubtestItem = createMockTestItem(subtestName); // add a mock test item to the map of known VSCode ids to run ids resultResolver.runIdToVSid.set('mockTestItem2', 'mockTestItem2'); // creates a mock test item with a space which will be used to split the runId - resultResolver.runIdToVSid.set('parentTest [subTest with spaces]', 'parentTest [subTest with spaces]'); + resultResolver.runIdToVSid.set(subtestName, subtestName); // add this mock test to the map of known test items resultResolver.runIdToTestItem.set('parentTest', mockTestItem2); - resultResolver.runIdToTestItem.set('parentTest [subTest with spaces]', mockSubtestItem); + resultResolver.runIdToTestItem.set(subtestName, mockSubtestItem); let generatedId: string | undefined; testControllerMock @@ -294,12 +295,12 @@ suite('Result Resolver tests', () => { cwd: workspaceUri.fsPath, status: 'success', result: { - 'parentTest [subTest with spaces]': { + 'parentTest [subTest with spaces and [brackets]]': { test: 'parentTest', outcome: 'subtest-success', // failure, passed-unexpected, skipped, success, expected-failure, subtest-failure, subtest-succcess message: 'message', traceback: 'traceback', - subtest: 'parentTest [subTest with spaces]', + subtest: subtestName, }, }, error: '', @@ -310,7 +311,7 @@ suite('Result Resolver tests', () => { // verify that the passed function was called for the single test item assert.ok(generatedId); - assert.strictEqual(generatedId, '[subTest with spaces]'); + assert.strictEqual(generatedId, '[subTest with spaces and [brackets]]'); }); test('resolveExecution handles failed tests correctly', async () => { // test specific constants used expected values