forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathbuildErrorNodeOptions.unit.test.ts
More file actions
51 lines (37 loc) · 2.25 KB
/
buildErrorNodeOptions.unit.test.ts
File metadata and controls
51 lines (37 loc) · 2.25 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { expect } from 'chai';
import { Uri } from 'vscode';
import { buildErrorNodeOptions } from '../../../../client/testing/testController/common/utils';
suite('buildErrorNodeOptions - pytest not installed detection', () => {
const workspaceUri = Uri.file('/test/workspace');
test('Should detect pytest ModuleNotFoundError and provide specific message', () => {
const errorMessage =
'Traceback (most recent call last):\n File "<string>", line 1, in <module>\n import pytest\nModuleNotFoundError: No module named \'pytest\'';
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'pytest');
expect(result.label).to.equal('pytest Not Installed [workspace]');
expect(result.error).to.equal(
'pytest is not installed in the selected Python environment. Please install pytest to enable test discovery and execution.',
);
});
test('Should detect pytest ImportError and provide specific message', () => {
const errorMessage = 'ImportError: No module named pytest';
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'pytest');
expect(result.label).to.equal('pytest Not Installed [workspace]');
expect(result.error).to.equal(
'pytest is not installed in the selected Python environment. Please install pytest to enable test discovery and execution.',
);
});
test('Should use generic error for non-pytest-related errors', () => {
const errorMessage = 'Some other error occurred';
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'pytest');
expect(result.label).to.equal('pytest Discovery Error [workspace]');
expect(result.error).to.equal('Some other error occurred');
});
test('Should use generic error for unittest errors', () => {
const errorMessage = "ModuleNotFoundError: No module named 'pytest'";
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'unittest');
expect(result.label).to.equal('Unittest Discovery Error [workspace]');
expect(result.error).to.equal("ModuleNotFoundError: No module named 'pytest'");
});
});