Skip to content

Commit 83d0cc6

Browse files
Nikolay Kondratyevericsnowcurrently
Nikolay Kondratyev
authored andcommitted
Fix the "nameToRun" for test files in unittest results. (#7783)
For gh-4567.
1 parent 9f94cfb commit 83d0cc6

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

news/2 Fixes/4567.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix running a unittest file executing only the first test
2+
(thanks [Nikolay Kondratyev](https://github.com/kondratyev-nv/))

src/client/testing/unittest/services/parserService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class TestsParser implements ITestsParser {
6565
const functionName = testIdParts.pop()!;
6666
const suiteToRun = testIdParts.join('.');
6767
const className = testIdParts.pop()!;
68+
const moduleName = testIdParts.join('.');
6869
const resource = Uri.file(rootDirectory);
6970

7071
// Check if we already have this test file
@@ -76,7 +77,7 @@ export class TestsParser implements ITestsParser {
7677
fullPath: filePath,
7778
functions: [],
7879
suites: [],
79-
nameToRun: `${suiteToRun}.${functionName}`,
80+
nameToRun: moduleName,
8081
xmlName: '',
8182
status: TestStatus.Idle,
8283
time: 0

src/test/testing/unittest/unittest.discovery.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ suite('Unit Tests - unittest - discovery with mocked process output', () => {
102102
assert.equal(tests.testFiles.length, 1, 'Incorrect number of test files');
103103
assert.equal(tests.testFunctions.length, 3, 'Incorrect number of test functions');
104104
assert.equal(tests.testSuites.length, 1, 'Incorrect number of test suites');
105-
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one.Test_test1.test_A'), true, 'Test File not found');
105+
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one'), true, 'Test File not found');
106+
assert.equal(tests.testFunctions.some(t => t.testFunction.name === 'test_A' && t.testFunction.nameToRun === 'test_one.Test_test1.test_A'), true, 'Test File not found');
106107
});
107108

108109
test('Discover Tests', async () => {
@@ -125,8 +126,10 @@ suite('Unit Tests - unittest - discovery with mocked process output', () => {
125126
assert.equal(tests.testFiles.length, 2, 'Incorrect number of test files');
126127
assert.equal(tests.testFunctions.length, 9, 'Incorrect number of test functions');
127128
assert.equal(tests.testSuites.length, 3, 'Incorrect number of test suites');
128-
assert.equal(tests.testFiles.some(t => t.name === 'test_unittest_one.py' && t.nameToRun === 'test_unittest_one.Test_test1.test_A'), true, 'Test File not found');
129-
assert.equal(tests.testFiles.some(t => t.name === 'test_unittest_two.py' && t.nameToRun === 'test_unittest_two.Test_test2.test_A2'), true, 'Test File not found');
129+
assert.equal(tests.testFiles.some(t => t.name === 'test_unittest_one.py' && t.nameToRun === 'test_unittest_one'), true, 'Test File not found');
130+
assert.equal(tests.testFiles.some(t => t.name === 'test_unittest_two.py' && t.nameToRun === 'test_unittest_two'), true, 'Test File not found');
131+
assert.equal(tests.testFunctions.some(t => t.testFunction.name === 'test_A' && t.testFunction.nameToRun === 'test_unittest_one.Test_test1.test_A'), true, 'Test File not found');
132+
assert.equal(tests.testFunctions.some(t => t.testFunction.name === 'test_A2' && t.testFunction.nameToRun === 'test_unittest_two.Test_test2.test_A2'), true, 'Test File not found');
130133
});
131134

132135
test('Discover Tests (pattern = *_test_*.py)', async () => {
@@ -142,7 +145,8 @@ suite('Unit Tests - unittest - discovery with mocked process output', () => {
142145
assert.equal(tests.testFiles.length, 1, 'Incorrect number of test files');
143146
assert.equal(tests.testFunctions.length, 2, 'Incorrect number of test functions');
144147
assert.equal(tests.testSuites.length, 1, 'Incorrect number of test suites');
145-
assert.equal(tests.testFiles.some(t => t.name === 'unittest_three_test.py' && t.nameToRun === 'unittest_three_test.Test_test3.test_A'), true, 'Test File not found');
148+
assert.equal(tests.testFiles.some(t => t.name === 'unittest_three_test.py' && t.nameToRun === 'unittest_three_test'), true, 'Test File not found');
149+
assert.equal(tests.testFunctions.some(t => t.testFunction.name === 'test_A' && t.testFunction.nameToRun === 'unittest_three_test.Test_test3.test_A'), true, 'Test File not found');
146150
});
147151

148152
test('Setting cwd should return tests', async () => {

src/test/testing/unittest/unittest.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ suite('Unit Tests - unittest - discovery against actual python process', () => {
8080
assert.equal(tests.testFiles.length, 1, 'Incorrect number of test files');
8181
assert.equal(tests.testFunctions.length, 3, 'Incorrect number of test functions');
8282
assert.equal(tests.testSuites.length, 1, 'Incorrect number of test suites');
83-
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one.Test_test1.test_A'), true, 'Test File not found');
83+
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one'), true, 'Test File not found');
84+
assert.equal(tests.testFunctions.some(t => t.testFunction.name === 'test_A' && t.testFunction.nameToRun === 'test_one.Test_test1.test_A'), true, 'Test File not found');
8485
});
8586

8687
test('Discover Tests (many test files, subdir included)', async () => {
@@ -91,9 +92,12 @@ suite('Unit Tests - unittest - discovery against actual python process', () => {
9192
assert.equal(tests.testFiles.length, 3, 'Incorrect number of test files');
9293
assert.equal(tests.testFunctions.length, 9, 'Incorrect number of test functions');
9394
assert.equal(tests.testSuites.length, 3, 'Incorrect number of test suites');
94-
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one.Test_test1.test_A'), true, 'Test File one not found');
95-
assert.equal(tests.testFiles.some(t => t.name === 'test_two.py' && t.nameToRun === 'test_two.Test_test2.test_2A'), true, 'Test File two not found');
96-
assert.equal(tests.testFiles.some(t => t.name === 'test_three.py' && t.nameToRun === 'more_tests.test_three.Test_test3.test_3A'), true, 'Test File three not found');
95+
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one'), true, 'Test File one not found');
96+
assert.equal(tests.testFiles.some(t => t.name === 'test_two.py' && t.nameToRun === 'test_two'), true, 'Test File two not found');
97+
assert.equal(tests.testFiles.some(t => t.name === 'test_three.py' && t.nameToRun === 'more_tests.test_three'), true, 'Test File three not found');
98+
assert.equal(tests.testFunctions.some(t => t.testFunction.name === 'test_A' && t.testFunction.nameToRun === 'test_one.Test_test1.test_A'), true, 'Test File one not found');
99+
assert.equal(tests.testFunctions.some(t => t.testFunction.name === 'test_2A' && t.testFunction.nameToRun === 'test_two.Test_test2.test_2A'), true, 'Test File two not found');
100+
assert.equal(tests.testFunctions.some(t => t.testFunction.name === 'test_3A' && t.testFunction.nameToRun === 'more_tests.test_three.Test_test3.test_3A'), true, 'Test File three not found');
97101
});
98102

99103
test('Run single test', async () => {
@@ -102,7 +106,7 @@ suite('Unit Tests - unittest - discovery against actual python process', () => {
102106
const testManager = factory('unittest', rootWorkspaceUri!, UNITTEST_MULTI_TEST_FILE_PATH);
103107
const testsDiscovered: Tests = await testManager.discoverTests(CommandSource.ui, true, true);
104108
const testFile: TestFile | undefined = testsDiscovered.testFiles.find(
105-
(value: TestFile) => value.nameToRun.endsWith('_3A')
109+
(value: TestFile) => value.nameToRun.endsWith('_three')
106110
);
107111
assert.notEqual(testFile, undefined, 'No test file suffixed with _3A in test files.');
108112
assert.equal(testFile!.suites.length, 1, 'Expected only 1 test suite in test file three.');

0 commit comments

Comments
 (0)