forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuildErrorNodeOptions.unit.test.ts
More file actions
85 lines (62 loc) · 3.82 KB
/
buildErrorNodeOptions.unit.test.ts
File metadata and controls
85 lines (62 loc) · 3.82 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
// 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 - missing module detection', () => {
const workspaceUri = Uri.file('/test/workspace');
test('Should detect pytest ModuleNotFoundError and show missing module label', () => {
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('Missing Module: pytest [workspace]');
expect(result.error).to.equal(
"The module 'pytest' is not installed in the selected Python environment. Please install it to enable test discovery.",
);
});
test('Should detect pytest ImportError and show missing module label', () => {
const errorMessage = 'ImportError: No module named pytest';
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'pytest');
expect(result.label).to.equal('Missing Module: pytest [workspace]');
expect(result.error).to.equal(
"The module 'pytest' is not installed in the selected Python environment. Please install it to enable test discovery.",
);
});
test('Should detect other missing modules and show module name in label', () => {
const errorMessage =
"bob\\test_bob.py:3: in <module>\n import requests\nE ModuleNotFoundError: No module named 'requests'\n=========================== short test summary info";
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'pytest');
expect(result.label).to.equal('Missing Module: requests [workspace]');
expect(result.error).to.equal(
"The module 'requests' is not installed in the selected Python environment. Please install it to enable test discovery.",
);
});
test('Should detect missing module with double quotes', () => {
const errorMessage = 'ModuleNotFoundError: No module named "numpy"';
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'pytest');
expect(result.label).to.equal('Missing Module: numpy [workspace]');
expect(result.error).to.equal(
"The module 'numpy' is not installed in the selected Python environment. Please install it to enable test discovery.",
);
});
test('Should use generic error for non-module-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 detect missing module for unittest errors', () => {
const errorMessage = "ModuleNotFoundError: No module named 'pandas'";
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'unittest');
expect(result.label).to.equal('Missing Module: pandas [workspace]');
expect(result.error).to.equal(
"The module 'pandas' is not installed in the selected Python environment. Please install it to enable test discovery.",
);
});
test('Should use generic error for unittest non-module errors', () => {
const errorMessage = 'Some other error occurred';
const result = buildErrorNodeOptions(workspaceUri, errorMessage, 'unittest');
expect(result.label).to.equal('Unittest Discovery Error [workspace]');
expect(result.error).to.equal('Some other error occurred');
});
});