diff --git a/news/1 Enhancements/704.md b/news/1 Enhancements/704.md new file mode 100644 index 000000000000..49f1c4d9a3b8 --- /dev/null +++ b/news/1 Enhancements/704.md @@ -0,0 +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. diff --git a/src/client/unittests/display/main.ts b/src/client/unittests/display/main.ts index b6f03f11c62f..aec0139ac2cb 100644 --- a/src/client/unittests/display/main.ts +++ b/src/client/unittests/display/main.ts @@ -11,9 +11,9 @@ export class TestResultDisplay { private discoverCounter = 0; private ticker = ['|', '/', '-', '|', '/', '-', '\\']; private progressTimeout; - private progressPrefix: string; + private progressPrefix!: string; // tslint:disable-next-line:no-any - constructor(private outputChannel: vscode.OutputChannel, private onDidChange?: vscode.EventEmitter) { + constructor(private onDidChange?: vscode.EventEmitter) { this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); } public dispose() { @@ -35,10 +35,10 @@ export class TestResultDisplay { // tslint:disable-next-line:no-empty .catch(() => { }); } - public displayDiscoverStatus(testDiscovery: Promise) { + public displayDiscoverStatus(testDiscovery: Promise, quietMode: boolean = false) { this.displayProgress('Discovering Tests', 'Discovering Tests (Click to Stop)', constants.Commands.Tests_Ask_To_Stop_Discovery); return testDiscovery.then(tests => { - this.updateWithDiscoverSuccess(tests); + this.updateWithDiscoverSuccess(tests, quietMode); return tests; }).catch(reason => { this.updateWithDiscoverFailure(reason); @@ -143,7 +143,7 @@ export class TestResultDisplay { return def.promise; } - private updateWithDiscoverSuccess(tests: Tests) { + private updateWithDiscoverSuccess(tests: Tests, quietMode: boolean = false) { this.clearProgressTicker(); const haveTests = tests && (tests.testFunctions.length > 0); this.statusBar.text = '$(zap) Run Tests'; @@ -154,7 +154,7 @@ export class TestResultDisplay { this.onDidChange.fire(); } - if (!haveTests) { + if (!haveTests && !quietMode) { vscode.window.showInformationMessage('No tests discovered, please check the configuration settings for the tests.', 'Disable Tests').then(item => { if (item === 'Disable Tests') { this.disableTests() diff --git a/src/client/unittests/main.ts b/src/client/unittests/main.ts index 2e386edea0b0..71bb3c2339b2 100644 --- a/src/client/unittests/main.ts +++ b/src/client/unittests/main.ts @@ -1,5 +1,6 @@ 'use strict'; import * as vscode from 'vscode'; +// tslint:disable-next-line:no-duplicate-imports import { Disposable, Uri, window, workspace } from 'vscode'; import { PythonSettings } from '../common/configSettings'; import * as constants from '../common/constants'; @@ -77,7 +78,7 @@ async function onDocumentSaved(doc: vscode.TextDocument): Promise { if (timeoutId) { clearTimeout(timeoutId); } - timeoutId = setTimeout(() => discoverTests(CommandSource.auto, doc.uri, true), 1000); + timeoutId = setTimeout(() => discoverTests(CommandSource.auto, doc.uri, true, false, true), 1000); } function dispose() { @@ -157,7 +158,7 @@ async function selectAndRunTestMethod(cmdSource: CommandSource, resource: Uri, d if (!selectedTestFn) { return; } - // tslint:disable-next-line:prefer-type-cast + // tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion await runTestsImpl(cmdSource, testManager.workspaceFolder, { testFunction: [selectedTestFn.testFunction] } as TestsToRun, false, debug); } async function selectAndRunTestFile(cmdSource: CommandSource) { @@ -177,7 +178,7 @@ async function selectAndRunTestFile(cmdSource: CommandSource) { if (!selectedFile) { return; } - // tslint:disable-next-line:prefer-type-cast + // tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion await runTestsImpl(cmdSource, testManager.workspaceFolder, { testFile: [selectedFile] } as TestsToRun); } async function runCurrentTestFile(cmdSource: CommandSource) { @@ -200,7 +201,7 @@ async function runCurrentTestFile(cmdSource: CommandSource) { if (testFiles.length < 1) { return; } - // tslint:disable-next-line:prefer-type-cast + // tslint:disable-next-line:prefer-type-cast no-object-literal-type-assertion await runTestsImpl(cmdSource, testManager.workspaceFolder, { testFile: [testFiles[0]] } as TestsToRun); } async function displayStopUI(message: string) { @@ -272,16 +273,16 @@ async function stopTests(resource: Uri) { testManager.stop(); } } -async function discoverTests(cmdSource: CommandSource, resource?: Uri, ignoreCache?: boolean, userInitiated?: boolean) { +async function discoverTests(cmdSource: CommandSource, resource?: Uri, ignoreCache?: boolean, userInitiated?: boolean, quietMode?: boolean) { const testManager = await getTestManager(true, resource); if (!testManager) { return; } if (testManager && (testManager.status !== TestStatus.Discovering && testManager.status !== TestStatus.Running)) { - testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(outChannel, onDidChange); - const discoveryPromise = testManager.discoverTests(cmdSource, ignoreCache, false, userInitiated); - testResultDisplay.displayDiscoverStatus(discoveryPromise) + testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(onDidChange); + const discoveryPromise = testManager.discoverTests(cmdSource, ignoreCache, quietMode, userInitiated); + testResultDisplay.displayDiscoverStatus(discoveryPromise, quietMode) .catch(ex => console.error('Python Extension: displayDiscoverStatus', ex)); await discoveryPromise; } @@ -292,7 +293,7 @@ async function runTestsImpl(cmdSource: CommandSource, resource?: Uri, testsToRun return; } - testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(outChannel, onDidChange); + testResultDisplay = testResultDisplay ? testResultDisplay : new TestResultDisplay(onDidChange); const promise = testManager.runTest(cmdSource, testsToRun, runFailedTests, debug) .catch(reason => { if (reason !== CANCELLATION_REASON) {