forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrediscover.test.ts
More file actions
93 lines (85 loc) · 4.62 KB
/
rediscover.test.ts
File metadata and controls
93 lines (85 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { assert } from 'chai';
import * as fs from 'fs-extra';
import * as path from 'path';
import { instance, mock } from 'ts-mockito';
import { ConfigurationTarget } from 'vscode';
import { ICondaService, IInterpreterService } from '../../client/interpreter/contracts';
import { InterpreterService } from '../../client/interpreter/interpreterService';
import { CondaService } from '../../client/interpreter/locators/services/condaService';
import { CommandSource } from '../../client/testing/common/constants';
import { ITestManagerFactory, TestProvider } from '../../client/testing/common/types';
import { deleteDirectory, deleteFile, rootWorkspaceUri, updateSetting } from '../common';
import { initialize, initializeTest, IS_MULTI_ROOT_TEST, TEST_TIMEOUT } from './../initialize';
import { UnitTestIocContainer } from './serviceRegistry';
const testFilesPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'testFiles', 'debuggerTest');
const testFile = path.join(testFilesPath, 'tests', 'test_debugger_two.py');
const testFileWithFewTests = path.join(testFilesPath, 'tests', 'test_debugger_two.txt');
const testFileWithMoreTests = path.join(testFilesPath, 'tests', 'test_debugger_two.updated.txt');
const defaultUnitTestArgs = ['-v', '-s', '.', '-p', '*test*.py'];
// tslint:disable-next-line:max-func-body-length
suite('Unit Tests re-discovery', () => {
let ioc: UnitTestIocContainer;
const configTarget = IS_MULTI_ROOT_TEST ? ConfigurationTarget.WorkspaceFolder : ConfigurationTarget.Workspace;
suiteSetup(async () => {
await initialize();
});
setup(async function() {
// tslint:disable-next-line:no-invalid-this
this.timeout(TEST_TIMEOUT * 2); // This hook requires more timeout as we're dealing with files as well
await fs.copy(testFileWithFewTests, testFile, { overwrite: true });
await deleteDirectory(path.join(testFilesPath, '.cache'));
await resetSettings();
await initializeTest();
initializeDI();
});
teardown(async () => {
await ioc.dispose();
await resetSettings();
await fs.copy(testFileWithFewTests, testFile, { overwrite: true });
await deleteFile(path.join(path.dirname(testFile), `${path.basename(testFile, '.py')}.pyc`));
});
async function resetSettings() {
await updateSetting('testing.unittestArgs', defaultUnitTestArgs, rootWorkspaceUri, configTarget);
await updateSetting('testing.nosetestArgs', [], rootWorkspaceUri, configTarget);
await updateSetting('testing.pytestArgs', [], rootWorkspaceUri, configTarget);
}
function initializeDI() {
ioc = new UnitTestIocContainer();
ioc.registerCommonTypes();
ioc.registerProcessTypes();
ioc.registerVariableTypes();
ioc.registerUnitTestTypes();
ioc.serviceManager.addSingletonInstance<ICondaService>(ICondaService, instance(mock(CondaService)));
ioc.serviceManager.addSingletonInstance<IInterpreterService>(
IInterpreterService,
instance(mock(InterpreterService))
);
}
async function discoverUnitTests(testProvider: TestProvider) {
const testManager = ioc.serviceContainer.get<ITestManagerFactory>(ITestManagerFactory)(
testProvider,
rootWorkspaceUri!,
testFilesPath
);
let tests = await testManager.discoverTests(CommandSource.ui, true, true);
assert.equal(tests.testFiles.length, 2, 'Incorrect number of test files');
assert.equal(tests.testSuites.length, 2, 'Incorrect number of test suites');
assert.equal(tests.testFunctions.length, 2, 'Incorrect number of test functions');
await deleteFile(path.join(path.dirname(testFile), `${path.basename(testFile, '.py')}.pyc`));
await fs.copy(testFileWithMoreTests, testFile, { overwrite: true });
tests = await testManager.discoverTests(CommandSource.ui, true, true);
assert.equal(tests.testFunctions.length, 4, 'Incorrect number of updated test functions');
}
test('Re-discover tests (unittest)', async () => {
await updateSetting('testing.unittestArgs', ['-s=./tests', '-p=test_*.py'], rootWorkspaceUri, configTarget);
await discoverUnitTests('unittest');
});
test('Re-discover tests (pytest)', async () => {
await updateSetting('testing.pytestArgs', ['-k=test_'], rootWorkspaceUri, configTarget);
await discoverUnitTests('pytest');
});
test('Re-discover tests (nosetest)', async () => {
await updateSetting('testing.nosetestArgs', ['-m', 'test'], rootWorkspaceUri, configTarget);
await discoverUnitTests('nosetest');
});
});