Skip to content

Commit 5416af2

Browse files
authored
Disable the display of errors messages when rediscovering of tests fail in response to changes to files (#1133)
* do not display discovery errors when auto rediscovering tests * 📝 news entry * code review changes [skip ci] * Fixes #704
1 parent 99403d6 commit 5416af2

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

news/1 Enhancements/704.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disable the display of errors messages when rediscovering of tests fail in response to changes to files, e.g. don't show a message if there's a syntax error in the test code.

src/client/unittests/display/main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export class TestResultDisplay {
1111
private discoverCounter = 0;
1212
private ticker = ['|', '/', '-', '|', '/', '-', '\\'];
1313
private progressTimeout;
14-
private progressPrefix: string;
14+
private progressPrefix!: string;
1515
// tslint:disable-next-line:no-any
16-
constructor(private outputChannel: vscode.OutputChannel, private onDidChange?: vscode.EventEmitter<any>) {
16+
constructor(private onDidChange?: vscode.EventEmitter<any>) {
1717
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
1818
}
1919
public dispose() {
@@ -35,10 +35,10 @@ export class TestResultDisplay {
3535
// tslint:disable-next-line:no-empty
3636
.catch(() => { });
3737
}
38-
public displayDiscoverStatus(testDiscovery: Promise<Tests>) {
38+
public displayDiscoverStatus(testDiscovery: Promise<Tests>, quietMode: boolean = false) {
3939
this.displayProgress('Discovering Tests', 'Discovering Tests (Click to Stop)', constants.Commands.Tests_Ask_To_Stop_Discovery);
4040
return testDiscovery.then(tests => {
41-
this.updateWithDiscoverSuccess(tests);
41+
this.updateWithDiscoverSuccess(tests, quietMode);
4242
return tests;
4343
}).catch(reason => {
4444
this.updateWithDiscoverFailure(reason);
@@ -143,7 +143,7 @@ export class TestResultDisplay {
143143
return def.promise;
144144
}
145145

146-
private updateWithDiscoverSuccess(tests: Tests) {
146+
private updateWithDiscoverSuccess(tests: Tests, quietMode: boolean = false) {
147147
this.clearProgressTicker();
148148
const haveTests = tests && (tests.testFunctions.length > 0);
149149
this.statusBar.text = '$(zap) Run Tests';
@@ -154,7 +154,7 @@ export class TestResultDisplay {
154154
this.onDidChange.fire();
155155
}
156156

157-
if (!haveTests) {
157+
if (!haveTests && !quietMode) {
158158
vscode.window.showInformationMessage('No tests discovered, please check the configuration settings for the tests.', 'Disable Tests').then(item => {
159159
if (item === 'Disable Tests') {
160160
this.disableTests()

src/client/unittests/main.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
import * as vscode from 'vscode';
3+
// tslint:disable-next-line:no-duplicate-imports
34
import { Disposable, Uri, window, workspace } from 'vscode';
45
import { PythonSettings } from '../common/configSettings';
56
import * as constants from '../common/constants';
@@ -77,7 +78,7 @@ async function onDocumentSaved(doc: vscode.TextDocument): Promise<void> {
7778
if (timeoutId) {
7879
clearTimeout(timeoutId);
7980
}
80-
timeoutId = setTimeout(() => discoverTests(CommandSource.auto, doc.uri, true), 1000);
81+
timeoutId = setTimeout(() => discoverTests(CommandSource.auto, doc.uri, true, false, true), 1000);
8182
}
8283

8384
function dispose() {
@@ -157,7 +158,7 @@ async function selectAndRunTestMethod(cmdSource: CommandSource, resource: Uri, d
157158
if (!selectedTestFn) {
158159
return;
159160
}
160-
// tslint:disable-next-line:prefer-type-cast
161+
// tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion
161162
await runTestsImpl(cmdSource, testManager.workspaceFolder, { testFunction: [selectedTestFn.testFunction] } as TestsToRun, false, debug);
162163
}
163164
async function selectAndRunTestFile(cmdSource: CommandSource) {
@@ -177,7 +178,7 @@ async function selectAndRunTestFile(cmdSource: CommandSource) {
177178
if (!selectedFile) {
178179
return;
179180
}
180-
// tslint:disable-next-line:prefer-type-cast
181+
// tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion
181182
await runTestsImpl(cmdSource, testManager.workspaceFolder, { testFile: [selectedFile] } as TestsToRun);
182183
}
183184
async function runCurrentTestFile(cmdSource: CommandSource) {
@@ -200,7 +201,7 @@ async function runCurrentTestFile(cmdSource: CommandSource) {
200201
if (testFiles.length < 1) {
201202
return;
202203
}
203-
// tslint:disable-next-line:prefer-type-cast
204+
// tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion
204205
await runTestsImpl(cmdSource, testManager.workspaceFolder, { testFile: [testFiles[0]] } as TestsToRun);
205206
}
206207
async function displayStopUI(message: string) {
@@ -272,16 +273,16 @@ async function stopTests(resource: Uri) {
272273
testManager.stop();
273274
}
274275
}
275-
async function discoverTests(cmdSource: CommandSource, resource?: Uri, ignoreCache?: boolean, userInitiated?: boolean) {
276+
async function discoverTests(cmdSource: CommandSource, resource?: Uri, ignoreCache?: boolean, userInitiated?: boolean, quietMode?: boolean) {
276277
const testManager = await getTestManager(true, resource);
277278
if (!testManager) {
278279
return;
279280
}
280281

281282
if (testManager && (testManager.status !== TestStatus.Discovering && testManager.status !== TestStatus.Running)) {
282-
testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(outChannel, onDidChange);
283-
const discoveryPromise = testManager.discoverTests(cmdSource, ignoreCache, false, userInitiated);
284-
testResultDisplay.displayDiscoverStatus(discoveryPromise)
283+
testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(onDidChange);
284+
const discoveryPromise = testManager.discoverTests(cmdSource, ignoreCache, quietMode, userInitiated);
285+
testResultDisplay.displayDiscoverStatus(discoveryPromise, quietMode)
285286
.catch(ex => console.error('Python Extension: displayDiscoverStatus', ex));
286287
await discoveryPromise;
287288
}
@@ -292,7 +293,7 @@ async function runTestsImpl(cmdSource: CommandSource, resource?: Uri, testsToRun
292293
return;
293294
}
294295

295-
testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(outChannel, onDidChange);
296+
testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(onDidChange);
296297
const promise = testManager.runTest(cmdSource, testsToRun, runFailedTests, debug)
297298
.catch(reason => {
298299
if (reason !== CANCELLATION_REASON) {

0 commit comments

Comments
 (0)