Skip to content

Commit 3e940ab

Browse files
committed
display errors when tests don't run #459
1 parent 26a4315 commit 3e940ab

2 files changed

Lines changed: 30 additions & 25 deletions

File tree

src/client/unittests/display/main.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export class TestResultDisplay {
6262
this.statusBar.text = statusText.length === 0 ? 'No Tests Ran' : statusText.join(' ');
6363
this.statusBar.color = foreColor;
6464
this.statusBar.command = constants.Commands.Tests_View_UI;
65+
66+
if (statusText.length === 0){
67+
vscode.window.showWarningMessage('No tests ran, please check the configuration settings for the tests.');
68+
}
6569
return tests;
6670
}
6771

@@ -105,33 +109,31 @@ export class TestResultDisplay {
105109
this.discoverCounter = 0;
106110
}
107111

108-
public DisplayDiscoverStatus(tests: Promise<Tests>, quietMode: boolean = false) {
112+
public DisplayDiscoverStatus(tests: Promise<Tests>) {
109113
this.displayProgress('Discovering Tests', 'Discovering Tests (Click to Stop)', constants.Commands.Tests_Ask_To_Stop_Discovery);
110114
return tests.then(tests => {
111-
this.updateWithDiscoverSuccess(tests, quietMode);
115+
this.updateWithDiscoverSuccess(tests);
112116
return tests;
113117
}).catch(reason => {
114-
this.updateWithDiscoverFailure(reason, quietMode);
118+
this.updateWithDiscoverFailure(reason);
115119
return Promise.reject(reason);
116120
});
117121
}
118122

119-
private updateWithDiscoverSuccess(tests: Tests, quietMode: boolean = false) {
123+
private updateWithDiscoverSuccess(tests: Tests) {
120124
this.clearProgressTicker();
121125
const haveTests = tests && (tests.testFunctions.length > 0);
122126
this.statusBar.text = haveTests ? '$(zap) Run Tests' : 'No Tests';
123127
this.statusBar.tooltip = haveTests ? 'Run Tests' : 'No Tests discovered';
124128
this.statusBar.command = haveTests ? constants.Commands.Tests_View_UI : constants.Commands.Tests_Discover;
125129
this.statusBar.show();
126130

127-
if (!haveTests && !quietMode) {
128-
// TODO: show an option that will invoke a command 'python.test.configureTest' or similar
129-
// This will be hanlded by main.ts that will capture input from user and configure the tests
130-
vscode.window.showInformationMessage('No Tests discovered');
131+
if (!haveTests) {
132+
vscode.window.showInformationMessage('No tests discovered, please check the configuration settings for the tests.');
131133
}
132134
}
133135

134-
private updateWithDiscoverFailure(reason: any, quietMode: boolean = false) {
136+
private updateWithDiscoverFailure(reason: any) {
135137
this.clearProgressTicker();
136138
this.statusBar.text = `$(zap) Discover Tests`;
137139
this.statusBar.tooltip = 'Discover Tests';
@@ -142,10 +144,10 @@ export class TestResultDisplay {
142144
this.statusBar.text = `$(alert) Test discovery failed`;
143145
this.statusBar.tooltip = `Discovering Tests failed (view 'Python Test Log' output panel for details)`;
144146
// TODO: ignore this quitemode, always display the error message (inform the user)
145-
if (!isNotInstalledError(reason) && !quietMode) {
147+
if (!isNotInstalledError(reason)) {
146148
// TODO: show an option that will invoke a command 'python.test.configureTest' or similar
147149
// This will be hanlded by main.ts that will capture input from user and configure the tests
148-
vscode.window.showErrorMessage('There was an error in discovering tests');
150+
vscode.window.showErrorMessage('There was an error in discovering tests, please check the configuration settings for the tests.');
149151
}
150152
}
151153
}

src/client/unittests/main.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ export function activate(context: vscode.ExtensionContext, outputChannel: vscode
2727
outChannel = outputChannel;
2828
let disposables = registerCommands();
2929
context.subscriptions.push(...disposables);
30-
// Ignore the exceptions returned
31-
// This function is invoked via a command which will be invoked else where in the extension
32-
discoverTests(true, true).catch(() => {
33-
// Ignore the errors
34-
let x = '';
35-
});
30+
31+
if (settings.unitTest.nosetestsEnabled || settings.unitTest.pyTestEnabled || settings.unitTest.unittestEnabled) {
32+
// Ignore the exceptions returned
33+
// This function is invoked via a command which will be invoked else where in the extension
34+
discoverTests(true).catch(() => {
35+
// Ignore the errors
36+
});
37+
}
38+
3639
settings.addListener('change', onConfigChanged);
3740
context.subscriptions.push(activateCodeLenses());
3841

@@ -51,10 +54,10 @@ function dispose() {
5154
}
5255
function registerCommands(): vscode.Disposable[] {
5356
const disposables = [];
54-
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Discover, (quiteMode: boolean) => {
57+
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Discover, () => {
5558
// Ignore the exceptions returned
5659
// This command will be invoked else where in the extension
57-
discoverTests(true, quiteMode).catch(() => { return null; });
60+
discoverTests(true).catch(() => { return null; });
5861
}));
5962
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run_Failed, () => runTestsImpl(true)));
6063
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run, (testId) => runTestsImpl(testId)));
@@ -149,7 +152,9 @@ function onConfigChanged() {
149152
}
150153

151154
// No need to display errors
152-
discoverTests(true, true);
155+
if (settings.unitTest.nosetestsEnabled || settings.unitTest.pyTestEnabled || settings.unitTest.unittestEnabled) {
156+
discoverTests(true);
157+
}
153158
}
154159
function getTestRunner() {
155160
const rootDirectory = vscode.workspace.rootPath;
@@ -171,18 +176,16 @@ function stopTests() {
171176
testManager.stop();
172177
}
173178
}
174-
function discoverTests(ignoreCache?: boolean, quietMode: boolean = false) {
179+
function discoverTests(ignoreCache?: boolean) {
175180
let testManager = getTestRunner();
176181
if (!testManager) {
177-
if (!quietMode) {
178-
displayTestFrameworkError(outChannel);
179-
}
182+
displayTestFrameworkError(outChannel);
180183
return Promise.resolve(null);
181184
}
182185

183186
if (testManager && (testManager.status !== TestStatus.Discovering && testManager.status !== TestStatus.Running)) {
184187
testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(outChannel);
185-
return testResultDisplay.DisplayDiscoverStatus(testManager.discoverTests(ignoreCache, quietMode), quietMode);
188+
return testResultDisplay.DisplayDiscoverStatus(testManager.discoverTests(ignoreCache));
186189
}
187190
else {
188191
return Promise.resolve(null);

0 commit comments

Comments
 (0)