diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 633d9426ba74..078f16541509 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -407,9 +407,13 @@ export namespace Testing { export const testNotConfigured = l10n.t('No test framework configured.'); export const cancelUnittestDiscovery = l10n.t('Canceled unittest test discovery'); export const errorUnittestDiscovery = l10n.t('Unittest test discovery error'); + export const cancelPytestDiscovery = l10n.t('Canceled pytest test discovery'); + export const errorPytestDiscovery = l10n.t('pytest test discovery error'); export const seePythonOutput = l10n.t('(see Output > Python)'); export const cancelUnittestExecution = l10n.t('Canceled unittest test execution'); export const errorUnittestExecution = l10n.t('Unittest test execution error'); + export const cancelPytestExecution = l10n.t('Canceled pytest test execution'); + export const errorPytestExecution = l10n.t('Pytest test execution error'); } export namespace OutdatedDebugger { diff --git a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts index b9df9bb30725..792826f4c3a5 100644 --- a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts +++ b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts @@ -80,15 +80,11 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { resource: uri, }; const execService = await executionFactory.createActivatedEnvironment(creationOptions); - - try { - execService.exec( - ['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs), - spawnOptions, - ); - } catch (ex) { - console.error(ex); - } + execService + .exec(['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs), spawnOptions) + .catch((ex) => { + deferred.reject(ex as Error); + }); return deferred.promise; } } diff --git a/src/client/testing/testController/workspaceTestAdapter.ts b/src/client/testing/testController/workspaceTestAdapter.ts index b339256c3e08..39efc67f7c7e 100644 --- a/src/client/testing/testController/workspaceTestAdapter.ts +++ b/src/client/testing/testController/workspaceTestAdapter.ts @@ -120,14 +120,17 @@ export class WorkspaceTestAdapter { // handle token and telemetry here sendTelemetryEvent(EventName.UNITTEST_RUN_ALL_FAILED, undefined); - const cancel = token?.isCancellationRequested + let cancel = token?.isCancellationRequested ? Testing.cancelUnittestExecution : Testing.errorUnittestExecution; + if (this.testProvider === 'pytest') { + cancel = token?.isCancellationRequested ? Testing.cancelPytestExecution : Testing.errorPytestExecution; + } traceError(`${cancel}\r\n`, ex); // Also report on the test view const message = util.format(`${cancel} ${Testing.seePythonOutput}\r\n`, ex); - const options = buildErrorNodeOptions(this.workspaceUri, message); + const options = buildErrorNodeOptions(this.workspaceUri, message, this.testProvider); const errorNode = createErrorTestItem(testController, options); testController.items.add(errorNode); @@ -310,15 +313,18 @@ export class WorkspaceTestAdapter { } catch (ex) { sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, undefined, { tool: this.testProvider, failed: true }); - const cancel = token?.isCancellationRequested + let cancel = token?.isCancellationRequested ? Testing.cancelUnittestDiscovery : Testing.errorUnittestDiscovery; + if (this.testProvider === 'pytest') { + cancel = token?.isCancellationRequested ? Testing.cancelPytestDiscovery : Testing.errorPytestDiscovery; + } traceError(`${cancel}\r\n`, ex); // Report also on the test view. const message = util.format(`${cancel} ${Testing.seePythonOutput}\r\n`, ex); - const options = buildErrorNodeOptions(this.workspaceUri, message); + const options = buildErrorNodeOptions(this.workspaceUri, message, this.testProvider); const errorNode = createErrorTestItem(testController, options); testController.items.add(errorNode); @@ -336,17 +342,19 @@ export class WorkspaceTestAdapter { // Check if there were any errors in the discovery process. if (rawTestData.status === 'error') { + const testingErrorConst = + this.testProvider === 'pytest' ? Testing.errorPytestDiscovery : Testing.errorUnittestDiscovery; const { errors } = rawTestData; - traceError(Testing.errorUnittestDiscovery, '\r\n', errors!.join('\r\n\r\n')); + traceError(testingErrorConst, '\r\n', errors!.join('\r\n\r\n')); let errorNode = testController.items.get(`DiscoveryError:${workspacePath}`); const message = util.format( - `${Testing.errorUnittestDiscovery} ${Testing.seePythonOutput}\r\n`, + `${testingErrorConst} ${Testing.seePythonOutput}\r\n`, errors!.join('\r\n\r\n'), ); if (errorNode === undefined) { - const options = buildErrorNodeOptions(this.workspaceUri, message); + const options = buildErrorNodeOptions(this.workspaceUri, message, this.testProvider); errorNode = createErrorTestItem(testController, options); testController.items.add(errorNode); } @@ -462,10 +470,11 @@ function populateTestTree( }); } -function buildErrorNodeOptions(uri: Uri, message: string): ErrorTestItemOptions { +function buildErrorNodeOptions(uri: Uri, message: string, testType: string): ErrorTestItemOptions { + const labelText = testType === 'pytest' ? 'Pytest Discovery Error' : 'Unittest Discovery Error'; return { id: `DiscoveryError:${uri.fsPath}`, - label: `Unittest Discovery Error [${path.basename(uri.fsPath)}]`, + label: `${labelText} [${path.basename(uri.fsPath)}]`, error: message, }; }