@@ -5,7 +5,7 @@ import * as nosetests from './nosetest/main';
5
5
import * as pytest from './pytest/main' ;
6
6
import { resolveValueAsTestToRun } from './common/testUtils' ;
7
7
import { BaseTestManager } from './common/baseTestManager' ;
8
- import { PythonSettings } from '../common/configSettings' ;
8
+ import { PythonSettings , IUnitTestSettings } from '../common/configSettings' ;
9
9
import { TestResultDisplay } from './display/main' ;
10
10
import { TestFileCodeLensProvider } from './testFileCodeLensProvider' ;
11
11
import { TestDisplay } from './display/picker' ;
@@ -29,7 +29,10 @@ export function activate(context: vscode.ExtensionContext, outputChannel: vscode
29
29
context . subscriptions . push ( ...disposables ) ;
30
30
// Ignore the exceptions returned
31
31
// This function is invoked via a command which will be invoked else where in the extension
32
- discoverTests ( ) . catch ( ( ) => { } ) ;
32
+ discoverTests ( true , true ) . catch ( ( ) => {
33
+ // Ignore the errors
34
+ let x = '' ;
35
+ } ) ;
33
36
settings . addListener ( 'change' , onConfigChanged ) ;
34
37
}
35
38
function dispose ( ) {
@@ -57,22 +60,69 @@ function registerCommands(): vscode.Disposable[] {
57
60
}
58
61
59
62
function displayUI ( ) {
63
+ let testManager = getTestRunner ( ) ;
64
+ if ( ! testManager ) {
65
+ return displayTestFrameworkError ( ) ;
66
+ }
67
+
60
68
testDisplay = testDisplay ? testDisplay : new TestDisplay ( ) ;
61
69
testDisplay . displayTestUI ( ) ;
62
70
}
63
71
64
- let uniTestSettings = JSON . stringify ( settings . unitTest ) ;
72
+ let uniTestSettingsString = JSON . stringify ( settings . unitTest ) ;
65
73
66
74
function onConfigChanged ( ) {
67
75
// Possible that a test framework has been enabled or some settings have changed
68
76
// Meaning we need to re-load the discovered tests (as something could have changed)
69
77
const newSettings = JSON . stringify ( settings . unitTest ) ;
70
- if ( uniTestSettings !== newSettings ) {
71
- uniTestSettings = newSettings ;
72
- discoverTests ( ) ;
78
+ if ( uniTestSettingsString === newSettings ) {
79
+ return ;
80
+ }
81
+
82
+ uniTestSettingsString = newSettings ;
83
+ if ( ! settings . unitTest . nosetestsEnabled && ! settings . unitTest . pyTestEnabled ) {
84
+ if ( testResultDisplay ) {
85
+ testResultDisplay . enabled = false ;
86
+ }
87
+
88
+ if ( testManager ) {
89
+ testManager . stop ( ) ;
90
+ testManager = null ;
91
+ }
92
+ if ( pyTestManager ) {
93
+ pyTestManager . dispose ( ) ;
94
+ pyTestManager = null ;
95
+ }
96
+ if ( nosetestManager ) {
97
+ nosetestManager . dispose ( ) ;
98
+ nosetestManager = null ;
99
+ }
100
+ return ;
73
101
}
102
+
103
+ if ( testResultDisplay ) {
104
+ testResultDisplay . enabled = true ;
105
+ }
106
+
107
+ // No need to display errors
108
+ discoverTests ( true , true ) ;
109
+ }
110
+ function displayTestFrameworkError ( ) {
111
+ if ( settings . unitTest . pyTestEnabled && settings . unitTest . nosetestsEnabled ) {
112
+ vscode . window . showErrorMessage ( "Enable only one of the test frameworks (nosetest or pytest), not both." )
113
+ }
114
+ else {
115
+ vscode . window . showInformationMessage ( 'Please enable one of the test frameworks (pytest or nosetest)' ) ;
116
+ }
117
+ return null ;
74
118
}
75
119
function getTestRunner ( ) {
120
+ if ( settings . unitTest . pyTestEnabled && settings . unitTest . nosetestsEnabled ) {
121
+ return null ;
122
+ }
123
+ else if ( settings . unitTest . nosetestsEnabled ) {
124
+ return nosetestManager = nosetestManager ? nosetestManager : new nosetests . TestManager ( vscode . workspace . rootPath , outChannel ) ;
125
+ }
76
126
if ( settings . unitTest . pyTestEnabled ) {
77
127
return pyTestManager = pyTestManager ? pyTestManager : new pytest . TestManager ( vscode . workspace . rootPath , outChannel ) ;
78
128
}
@@ -89,15 +139,16 @@ function stopTests() {
89
139
}
90
140
function discoverTests ( ignoreCache ?: boolean , quietMode : boolean = false ) {
91
141
let testManager = getTestRunner ( ) ;
142
+ if ( ! testManager ) {
143
+ if ( ! quietMode ) {
144
+ displayTestFrameworkError ( ) ;
145
+ }
146
+ return Promise . resolve ( null ) ;
147
+ }
92
148
93
149
if ( testManager && ( testManager . status !== TestStatus . Discovering && testManager . status !== TestStatus . Running ) ) {
94
- if ( quietMode === true ) {
95
- return testManager . discoverTests ( ignoreCache , quietMode ) ;
96
- }
97
- else {
98
- testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay ( outChannel ) ;
99
- return testResultDisplay . DisplayDiscoverStatus ( testManager . discoverTests ( ignoreCache ) ) ;
100
- }
150
+ testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay ( outChannel ) ;
151
+ return testResultDisplay . DisplayDiscoverStatus ( testManager . discoverTests ( ignoreCache , quietMode ) , quietMode ) ;
101
152
}
102
153
else {
103
154
return Promise . resolve ( null ) ;
@@ -131,8 +182,7 @@ function identifyTestType(arg?: vscode.Uri | TestsToRun | boolean | FlattenedTes
131
182
function runTestsImpl ( arg ?: vscode . Uri | TestsToRun | boolean | FlattenedTestFunction ) {
132
183
let testManager = getTestRunner ( ) ;
133
184
if ( ! testManager ) {
134
- vscode . window . showInformationMessage ( 'Please enable one of the test frameworks (pytest or nosetest)' ) ;
135
- return ;
185
+ return displayTestFrameworkError ( ) ;
136
186
}
137
187
138
188
// lastRanTests = testsToRun;
0 commit comments