Skip to content

Commit 76be167

Browse files
committed
add pytest msg to error logging
1 parent 67ef703 commit 76be167

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

src/client/common/utils/localize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,13 @@ export namespace Testing {
407407
export const testNotConfigured = l10n.t('No test framework configured.');
408408
export const cancelUnittestDiscovery = l10n.t('Canceled unittest test discovery');
409409
export const errorUnittestDiscovery = l10n.t('Unittest test discovery error');
410+
export const cancelPytestDiscovery = l10n.t('Canceled pytest test discovery');
411+
export const errorPytestDiscovery = l10n.t('pytest test discovery error');
410412
export const seePythonOutput = l10n.t('(see Output > Python)');
411413
export const cancelUnittestExecution = l10n.t('Canceled unittest test execution');
412414
export const errorUnittestExecution = l10n.t('Unittest test execution error');
415+
export const cancelPytestExecution = l10n.t('Canceled pytest test execution');
416+
export const errorPytestExecution = l10n.t('Pytest test execution error');
413417
}
414418

415419
export namespace OutdatedDebugger {

src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,11 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
8181
};
8282
const execService = await executionFactory.createActivatedEnvironment(creationOptions);
8383

84-
try {
85-
execService.exec(
86-
['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs),
87-
spawnOptions,
88-
);
89-
} catch (ex) {
90-
console.error(ex);
91-
}
84+
execService
85+
.exec(['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs), spawnOptions)
86+
.catch((ex) => {
87+
deferred.reject(ex as Error);
88+
});
9289
return deferred.promise;
9390
}
9491
}

src/client/testing/testController/workspaceTestAdapter.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ export class WorkspaceTestAdapter {
120120
// handle token and telemetry here
121121
sendTelemetryEvent(EventName.UNITTEST_RUN_ALL_FAILED, undefined);
122122

123-
const cancel = token?.isCancellationRequested
123+
let cancel = token?.isCancellationRequested
124124
? Testing.cancelUnittestExecution
125125
: Testing.errorUnittestExecution;
126+
if (this.testProvider === 'pytest') {
127+
cancel = token?.isCancellationRequested ? Testing.cancelPytestExecution : Testing.errorPytestExecution;
128+
}
126129
traceError(`${cancel}\r\n`, ex);
127130

128131
// Also report on the test view
129132
const message = util.format(`${cancel} ${Testing.seePythonOutput}\r\n`, ex);
130-
const options = buildErrorNodeOptions(this.workspaceUri, message);
133+
const options = buildErrorNodeOptions(this.workspaceUri, message, this.testProvider);
131134
const errorNode = createErrorTestItem(testController, options);
132135
testController.items.add(errorNode);
133136

@@ -310,15 +313,18 @@ export class WorkspaceTestAdapter {
310313
} catch (ex) {
311314
sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, undefined, { tool: this.testProvider, failed: true });
312315

313-
const cancel = token?.isCancellationRequested
316+
let cancel = token?.isCancellationRequested
314317
? Testing.cancelUnittestDiscovery
315318
: Testing.errorUnittestDiscovery;
319+
if (this.testProvider === 'pytest') {
320+
cancel = token?.isCancellationRequested ? Testing.cancelPytestDiscovery : Testing.errorPytestDiscovery;
321+
}
316322

317323
traceError(`${cancel}\r\n`, ex);
318324

319325
// Report also on the test view.
320326
const message = util.format(`${cancel} ${Testing.seePythonOutput}\r\n`, ex);
321-
const options = buildErrorNodeOptions(this.workspaceUri, message);
327+
const options = buildErrorNodeOptions(this.workspaceUri, message, this.testProvider);
322328
const errorNode = createErrorTestItem(testController, options);
323329
testController.items.add(errorNode);
324330

@@ -336,17 +342,19 @@ export class WorkspaceTestAdapter {
336342

337343
// Check if there were any errors in the discovery process.
338344
if (rawTestData.status === 'error') {
345+
const testingErrorConst =
346+
this.testProvider === 'pytest' ? Testing.errorPytestDiscovery : Testing.errorUnittestDiscovery;
339347
const { errors } = rawTestData;
340-
traceError(Testing.errorUnittestDiscovery, '\r\n', errors!.join('\r\n\r\n'));
348+
traceError(testingErrorConst, '\r\n', errors!.join('\r\n\r\n'));
341349

342350
let errorNode = testController.items.get(`DiscoveryError:${workspacePath}`);
343351
const message = util.format(
344-
`${Testing.errorUnittestDiscovery} ${Testing.seePythonOutput}\r\n`,
352+
`${testingErrorConst} ${Testing.seePythonOutput}\r\n`,
345353
errors!.join('\r\n\r\n'),
346354
);
347355

348356
if (errorNode === undefined) {
349-
const options = buildErrorNodeOptions(this.workspaceUri, message);
357+
const options = buildErrorNodeOptions(this.workspaceUri, message, this.testProvider);
350358
errorNode = createErrorTestItem(testController, options);
351359
testController.items.add(errorNode);
352360
}
@@ -462,10 +470,11 @@ function populateTestTree(
462470
});
463471
}
464472

465-
function buildErrorNodeOptions(uri: Uri, message: string): ErrorTestItemOptions {
473+
function buildErrorNodeOptions(uri: Uri, message: string, testType: string): ErrorTestItemOptions {
474+
const labelText = testType === 'pytest' ? 'Pytest Discovery Error' : 'Unittest Discovery Error';
466475
return {
467476
id: `DiscoveryError:${uri.fsPath}`,
468-
label: `Unittest Discovery Error [${path.basename(uri.fsPath)}]`,
477+
label: `${labelText} [${path.basename(uri.fsPath)}]`,
469478
error: message,
470479
};
471480
}

0 commit comments

Comments
 (0)