forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpytest.test.ts
More file actions
66 lines (62 loc) · 2.51 KB
/
pytest.test.ts
File metadata and controls
66 lines (62 loc) · 2.51 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
import * as assert from 'assert';
import * as path from 'path';
import * as vscode from 'vscode';
import { CommandSource } from '../../../client/common/application/types';
import { EXTENSION_ROOT_DIR } from '../../../client/common/constants';
import { ITestManagerFactory } from '../../../client/testing/common/types';
import { rootWorkspaceUri, updateSetting } from '../../common';
import { UnitTestIocContainer } from '../serviceRegistry';
import { initialize, initializeTest, IS_MULTI_ROOT_TEST } from '../../initialize';
const UNITTEST_SINGLE_TEST_FILE_PATH = path.join(
EXTENSION_ROOT_DIR,
'src',
'test',
'pythonFiles',
'testFiles',
'single',
);
suite('Unit Tests - pytest - discovery against actual python process', () => {
let ioc: UnitTestIocContainer;
const configTarget = IS_MULTI_ROOT_TEST
? vscode.ConfigurationTarget.WorkspaceFolder
: vscode.ConfigurationTarget.Workspace;
suiteSetup(async () => {
await initialize();
await updateSetting('testing.pytestArgs', [], rootWorkspaceUri, configTarget);
});
setup(async () => {
await initializeTest();
await initializeDI();
});
teardown(async () => {
await ioc.dispose();
await updateSetting('testing.pytestArgs', [], rootWorkspaceUri, configTarget);
});
async function initializeDI() {
ioc = new UnitTestIocContainer();
ioc.registerCommonTypes();
ioc.registerProcessTypes();
ioc.registerUnitTestTypes();
ioc.registerVariableTypes();
await ioc.registerMockInterpreterTypes();
ioc.registerInterpreterStorageTypes();
}
test('Discover Tests (single test file)', async () => {
const factory = ioc.serviceContainer.get<ITestManagerFactory>(ITestManagerFactory);
const testManager = factory('pytest', rootWorkspaceUri!, UNITTEST_SINGLE_TEST_FILE_PATH);
const tests = await testManager.discoverTests(CommandSource.ui, true, true);
assert.equal(tests.testFiles.length, 2, 'Incorrect number of test files');
assert.equal(tests.testFunctions.length, 6, 'Incorrect number of test functions');
assert.equal(tests.testSuites.length, 2, 'Incorrect number of test suites');
assert.equal(
tests.testFiles.some((t) => t.name === 'test_one.py'),
true,
'Test File not found',
);
assert.equal(
tests.testFiles.some((t) => t.name === 'test_root.py'),
true,
'Test File not found',
);
});
});