Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/2 Fixes/4567.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix running a unittest file executing only the first test
(thanks [Nikolay Kondratyev](https://github.com/kondratyev-nv/))
3 changes: 2 additions & 1 deletion src/client/testing/unittest/services/parserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class TestsParser implements ITestsParser {
const functionName = testIdParts.pop()!;
const suiteToRun = testIdParts.join('.');
const className = testIdParts.pop()!;
const moduleName = testIdParts.join('.');
const resource = Uri.file(rootDirectory);

// Check if we already have this test file
Expand All @@ -76,7 +77,7 @@ export class TestsParser implements ITestsParser {
fullPath: filePath,
functions: [],
suites: [],
nameToRun: `${suiteToRun}.${functionName}`,
nameToRun: moduleName,
xmlName: '',
status: TestStatus.Idle,
time: 0
Expand Down
12 changes: 8 additions & 4 deletions src/test/testing/unittest/unittest.discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ suite('Unit Tests - unittest - discovery with mocked process output', () => {
assert.equal(tests.testFiles.length, 1, 'Incorrect number of test files');
assert.equal(tests.testFunctions.length, 3, 'Incorrect number of test functions');
assert.equal(tests.testSuites.length, 1, 'Incorrect number of test suites');
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one.Test_test1.test_A'), true, 'Test File not found');
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one'), true, 'Test File not found');
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');
});

test('Discover Tests', async () => {
Expand All @@ -125,8 +126,10 @@ suite('Unit Tests - unittest - discovery with mocked process output', () => {
assert.equal(tests.testFiles.length, 2, 'Incorrect number of test files');
assert.equal(tests.testFunctions.length, 9, 'Incorrect number of test functions');
assert.equal(tests.testSuites.length, 3, 'Incorrect number of test suites');
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');
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');
assert.equal(tests.testFiles.some(t => t.name === 'test_unittest_one.py' && t.nameToRun === 'test_unittest_one'), true, 'Test File not found');
assert.equal(tests.testFiles.some(t => t.name === 'test_unittest_two.py' && t.nameToRun === 'test_unittest_two'), true, 'Test File not found');
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');
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');
});

test('Discover Tests (pattern = *_test_*.py)', async () => {
Expand All @@ -142,7 +145,8 @@ suite('Unit Tests - unittest - discovery with mocked process output', () => {
assert.equal(tests.testFiles.length, 1, 'Incorrect number of test files');
assert.equal(tests.testFunctions.length, 2, 'Incorrect number of test functions');
assert.equal(tests.testSuites.length, 1, 'Incorrect number of test suites');
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');
assert.equal(tests.testFiles.some(t => t.name === 'unittest_three_test.py' && t.nameToRun === 'unittest_three_test'), true, 'Test File not found');
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');
});

test('Setting cwd should return tests', async () => {
Expand Down
14 changes: 9 additions & 5 deletions src/test/testing/unittest/unittest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ suite('Unit Tests - unittest - discovery against actual python process', () => {
assert.equal(tests.testFiles.length, 1, 'Incorrect number of test files');
assert.equal(tests.testFunctions.length, 3, 'Incorrect number of test functions');
assert.equal(tests.testSuites.length, 1, 'Incorrect number of test suites');
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one.Test_test1.test_A'), true, 'Test File not found');
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one'), true, 'Test File not found');
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');
});

test('Discover Tests (many test files, subdir included)', async () => {
Expand All @@ -91,9 +92,12 @@ suite('Unit Tests - unittest - discovery against actual python process', () => {
assert.equal(tests.testFiles.length, 3, 'Incorrect number of test files');
assert.equal(tests.testFunctions.length, 9, 'Incorrect number of test functions');
assert.equal(tests.testSuites.length, 3, 'Incorrect number of test suites');
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');
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');
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');
assert.equal(tests.testFiles.some(t => t.name === 'test_one.py' && t.nameToRun === 'test_one'), true, 'Test File one not found');
assert.equal(tests.testFiles.some(t => t.name === 'test_two.py' && t.nameToRun === 'test_two'), true, 'Test File two not found');
assert.equal(tests.testFiles.some(t => t.name === 'test_three.py' && t.nameToRun === 'more_tests.test_three'), true, 'Test File three not found');
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');
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');
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');
});

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