Skip to content

Commit

Permalink
split subtest name to be unique second half (#21497)
Browse files Browse the repository at this point in the history
fixes: #21461
  • Loading branch information
eleanorjboyd authored Jun 27, 2023
1 parent bd5b622 commit 0307e91
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/client/testing/testController/common/resultResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export class PythonResultResolver implements ITestResultResolver {
} else if (rawTestExecData.result[keyTemp].outcome === 'subtest-failure') {
// 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];
const parentTestItem = this.runIdToTestItem.get(parentTestCaseId);
const data = rawTestExecData.result[keyTemp];
// find the subtest's parent test item
Expand All @@ -173,7 +174,6 @@ export class PythonResultResolver implements ITestResultResolver {
// clear since subtest items don't persist between runs
clearAllChildren(parentTestItem);
}
const subtestId = keyTemp;
const subTestItem = this.testController?.createTestItem(subtestId, subtestId);
runInstance.appendOutput(fixLogLines(`${subtestId} Failed\r\n`));
// create a new test item for the subtest
Expand All @@ -197,6 +197,7 @@ export class PythonResultResolver implements ITestResultResolver {
} 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];
const parentTestItem = this.runIdToTestItem.get(parentTestCaseId);

// find the subtest's parent test item
Expand All @@ -210,7 +211,6 @@ export class PythonResultResolver implements ITestResultResolver {
// clear since subtest items don't persist between runs
clearAllChildren(parentTestItem);
}
const subtestId = keyTemp;
const subTestItem = this.testController?.createTestItem(subtestId, subtestId);
// create a new test item for the subtest
if (subTestItem) {
Expand Down
53 changes: 53 additions & 0 deletions src/test/testing/testController/resultResolver.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { TestController, Uri, TestItem, CancellationToken, TestRun, TestItemCollection, Range } from 'vscode';
import * as typemoq from 'typemoq';
import * as sinon from 'sinon';
import * as assert from 'assert';
import { TestProvider } from '../../../client/testing/types';
import {
DiscoveredTestNode,
Expand Down Expand Up @@ -205,6 +206,58 @@ suite('Result Resolver tests', () => {
teardown(() => {
sinon.restore();
});
test('resolveExecution create correct subtest item for unittest', async () => {
// test specific constants used expected values
sinon.stub(testItemUtilities, 'clearAllChildren').callsFake(() => undefined);
testProvider = 'unittest';
workspaceUri = Uri.file('/foo/bar');
resultResolver = new ResultResolver.PythonResultResolver(
testControllerMock.object,
testProvider,
workspaceUri,
);
const mockSubtestItem = createMockTestItem('parentTest subTest');
// 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', 'parentTest subTest');

// add this mock test to the map of known test items
resultResolver.runIdToTestItem.set('parentTest', mockTestItem2);
resultResolver.runIdToTestItem.set('parentTest subTest', mockSubtestItem);

let generatedId: string | undefined;
testControllerMock
.setup((t) => t.createTestItem(typemoq.It.isAny(), typemoq.It.isAny()))
.callback((id: string) => {
generatedId = id;
console.log('createTestItem function called with id:', id);
})
.returns(() => ({ id: 'id_this', label: 'label_this', uri: workspaceUri } as TestItem));

// create a successful payload with a single test called mockTestItem1
const successPayload: ExecutionTestPayload = {
cwd: workspaceUri.fsPath,
status: 'success',
result: {
'parentTest subTest': {
test: 'test',
outcome: 'subtest-success', // failure, passed-unexpected, skipped, success, expected-failure, subtest-failure, subtest-succcess
message: 'message',
traceback: 'traceback',
subtest: 'subtest',
},
},
error: '',
};

// call resolveExecution
resultResolver.resolveExecution(successPayload, runInstance.object);

// verify that the passed function was called for the single test item
assert.ok(generatedId);
assert.strictEqual(generatedId, 'subTest');
});
test('resolveExecution handles failed tests correctly', async () => {
// test specific constants used expected values
testProvider = 'pytest';
Expand Down

0 comments on commit 0307e91

Please sign in to comment.