Skip to content

remove ITestLogChannel #24954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def pytest_internalerror(excrepr, excinfo): # noqa: ARG001
excinfo -- the exception information of type ExceptionInfo.
"""
# call.excinfo.exconly() returns the exception as a string.
ERRORS.append(excinfo.exconly() + "\n Check Python Test Logs for more details.")
ERRORS.append(excinfo.exconly() + "\n Check Python Logs for more details.")


def pytest_exception_interact(node, call, report):
Expand All @@ -139,9 +139,9 @@ def pytest_exception_interact(node, call, report):
if call.excinfo and call.excinfo.typename != "AssertionError":
if report.outcome == "skipped" and "SkipTest" in str(call):
return
ERRORS.append(call.excinfo.exconly() + "\n Check Python Test Logs for more details.")
ERRORS.append(call.excinfo.exconly() + "\n Check Python Logs for more details.")
else:
ERRORS.append(report.longreprtext + "\n Check Python Test Logs for more details.")
ERRORS.append(report.longreprtext + "\n Check Python Logs for more details.")
else:
# If during execution, send this data that the given node failed.
report_value = "error"
Expand Down Expand Up @@ -204,7 +204,7 @@ def pytest_keyboard_interrupt(excinfo):
excinfo -- the exception information of type ExceptionInfo.
"""
# The function execonly() returns the exception as a string.
ERRORS.append(excinfo.exconly() + "\n Check Python Test Logs for more details.")
ERRORS.append(excinfo.exconly() + "\n Check Python Logs for more details.")


class TestOutcome(Dict):
Expand Down
3 changes: 0 additions & 3 deletions src/client/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
Memento,
LogOutputChannel,
Uri,
OutputChannel,
} from 'vscode';
import { LanguageServerType } from '../activation/types';
import type { InstallOptions, InterpreterUri, ModuleInstallFlags } from './installer/types';
Expand All @@ -29,8 +28,6 @@ export interface IDisposable {

export const ILogOutputChannel = Symbol('ILogOutputChannel');
export interface ILogOutputChannel extends LogOutputChannel {}
export const ITestOutputChannel = Symbol('ITestOutputChannel');
export interface ITestOutputChannel extends OutputChannel {}
export const IDocumentSymbolProvider = Symbol('IDocumentSymbolProvider');
export interface IDocumentSymbolProvider extends DocumentSymbolProvider {}
export const IsWindows = Symbol('IS_WINDOWS');
Expand Down
1 change: 0 additions & 1 deletion src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ export namespace InterpreterQuickPickList {
export namespace OutputChannelNames {
export const languageServer = l10n.t('Python Language Server');
export const python = l10n.t('Python');
export const pythonTest = l10n.t('Python Test Log');
}

export namespace Linters {
Expand Down
11 changes: 1 addition & 10 deletions src/client/extensionInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

import { Container } from 'inversify';
import { Disposable, l10n, Memento, window } from 'vscode';
import { Disposable, Memento, window } from 'vscode';
import { registerTypes as platformRegisterTypes } from './common/platform/serviceRegistry';
import { registerTypes as processRegisterTypes } from './common/process/serviceRegistry';
import { registerTypes as commonRegisterTypes } from './common/serviceRegistry';
Expand All @@ -15,7 +15,6 @@ import {
IExtensionContext,
IMemento,
ILogOutputChannel,
ITestOutputChannel,
WORKSPACE_MEMENTO,
} from './common/types';
import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry';
Expand All @@ -28,7 +27,6 @@ import * as pythonEnvironments from './pythonEnvironments';
import { IDiscoveryAPI } from './pythonEnvironments/base/locator';
import { registerLogger } from './logging';
import { OutputChannelLogger } from './logging/outputChannelLogger';
import { isTrusted, isVirtualWorkspace } from './common/vscodeApis/workspaceApis';

// The code in this module should do nothing more complex than register
// objects to DI and simple init (e.g. no side effects). That implies
Expand Down Expand Up @@ -56,14 +54,7 @@ export function initializeGlobals(
disposables.push(standardOutputChannel);
disposables.push(registerLogger(new OutputChannelLogger(standardOutputChannel)));

const unitTestOutChannel = window.createOutputChannel(OutputChannelNames.pythonTest);
disposables.push(unitTestOutChannel);
if (isVirtualWorkspace() || !isTrusted()) {
unitTestOutChannel.appendLine(l10n.t('Unit tests are not supported in this environment.'));
}

serviceManager.addSingletonInstance<ILogOutputChannel>(ILogOutputChannel, standardOutputChannel);
serviceManager.addSingletonInstance<ITestOutputChannel>(ITestOutputChannel, unitTestOutChannel);

return {
context,
Expand Down
7 changes: 0 additions & 7 deletions src/client/testing/testController/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ export function fixLogLinesNoTrailing(content: string): string {
const lines = content.split(/\r?\n/g);
return `${lines.join('\r\n')}`;
}

export const MESSAGE_ON_TESTING_OUTPUT_MOVE =
'Starting now, all test run output will be sent to the Test Result panel,' +
' while test discovery output will be sent to the "Python" output channel instead of the "Python Test Log" channel.' +
' The "Python Test Log" channel will be deprecated within the next month.' +
' See https://github.com/microsoft/vscode-python/wiki/New-Method-for-Output-Handling-in-Python-Testing for details.';

export function createTestingDeferred(): Deferred<void> {
return createDeferred<void>();
}
Expand Down
7 changes: 1 addition & 6 deletions src/client/testing/testController/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { IExtensionSingleActivationService } from '../../activation/types';
import { ICommandManager, IWorkspaceService } from '../../common/application/types';
import * as constants from '../../common/constants';
import { IPythonExecutionFactory } from '../../common/process/types';
import { IConfigurationService, IDisposableRegistry, ITestOutputChannel, Resource } from '../../common/types';
import { IConfigurationService, IDisposableRegistry, Resource } from '../../common/types';
import { DelayedTrigger, IDelayedTrigger } from '../../common/utils/delayTrigger';
import { noop } from '../../common/utils/misc';
import { IInterpreterService } from '../../interpreter/contracts';
Expand Down Expand Up @@ -98,7 +98,6 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IPythonExecutionFactory) private readonly pythonExecFactory: IPythonExecutionFactory,
@inject(ITestDebugLauncher) private readonly debugLauncher: ITestDebugLauncher,
@inject(ITestOutputChannel) private readonly testOutputChannel: ITestOutputChannel,
@inject(IEnvironmentVariablesProvider) private readonly envVarsService: IEnvironmentVariablesProvider,
) {
this.refreshCancellation = new CancellationTokenSource();
Expand Down Expand Up @@ -176,13 +175,11 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
resultResolver = new PythonResultResolver(this.testController, testProvider, workspace.uri);
discoveryAdapter = new UnittestTestDiscoveryAdapter(
this.configSettings,
this.testOutputChannel,
resultResolver,
this.envVarsService,
);
executionAdapter = new UnittestTestExecutionAdapter(
this.configSettings,
this.testOutputChannel,
resultResolver,
this.envVarsService,
);
Expand All @@ -191,13 +188,11 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
resultResolver = new PythonResultResolver(this.testController, testProvider, workspace.uri);
discoveryAdapter = new PytestTestDiscoveryAdapter(
this.configSettings,
this.testOutputChannel,
resultResolver,
this.envVarsService,
);
executionAdapter = new PytestTestExecutionAdapter(
this.configSettings,
this.testOutputChannel,
resultResolver,
this.envVarsService,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import {
IPythonExecutionFactory,
SpawnOptions,
} from '../../../common/process/types';
import { IConfigurationService, ITestOutputChannel } from '../../../common/types';
import { IConfigurationService } from '../../../common/types';
import { createDeferred, Deferred } from '../../../common/utils/async';
import { EXTENSION_ROOT_DIR } from '../../../constants';
import { traceError, traceInfo, traceVerbose, traceWarn } from '../../../logging';
import { DiscoveredTestPayload, ITestDiscoveryAdapter, ITestResultResolver } from '../common/types';
import {
MESSAGE_ON_TESTING_OUTPUT_MOVE,
createDiscoveryErrorPayload,
createTestingDeferred,
fixLogLinesNoTrailing,
Expand All @@ -33,7 +32,6 @@ import { useEnvExtension, getEnvironment, runInBackground } from '../../../envEx
export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
constructor(
public configSettings: IConfigurationService,
private readonly outputChannel: ITestOutputChannel,
private readonly resultResolver?: ITestResultResolver,
private readonly envVarsService?: IEnvironmentVariablesProvider,
) {}
Expand Down Expand Up @@ -138,15 +136,12 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
proc.stdout.on('data', (data) => {
const out = fixLogLinesNoTrailing(data.toString());
traceInfo(out);
this.outputChannel?.append(out);
});
proc.stderr.on('data', (data) => {
const out = fixLogLinesNoTrailing(data.toString());
traceError(out);
this.outputChannel?.append(out);
});
proc.onExit((code, signal) => {
this.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE);
if (code !== 0) {
traceError(
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`,
Expand All @@ -165,7 +160,6 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
const spawnOptions: SpawnOptions = {
cwd,
throwOnStdErr: true,
outputChannel: this.outputChannel,
env: mutableEnv,
token,
};
Expand Down Expand Up @@ -200,20 +194,16 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {

// Take all output from the subprocess and add it to the test output channel. This will be the pytest output.
// Displays output to user and ensure the subprocess doesn't run into buffer overflow.
// TODO: after a release, remove discovery output from the "Python Test Log" channel and send it to the "Python" channel instead.

result?.proc?.stdout?.on('data', (data) => {
const out = fixLogLinesNoTrailing(data.toString());
traceInfo(out);
spawnOptions?.outputChannel?.append(`${out}`);
});
result?.proc?.stderr?.on('data', (data) => {
const out = fixLogLinesNoTrailing(data.toString());
traceError(out);
spawnOptions?.outputChannel?.append(`${out}`);
});
result?.proc?.on('exit', (code, signal) => {
this.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE);
if (code !== 0) {
traceError(
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { CancellationTokenSource, DebugSessionOptions, TestRun, TestRunProfileKind, Uri } from 'vscode';
import * as path from 'path';
import { ChildProcess } from 'child_process';
import { IConfigurationService, ITestOutputChannel } from '../../../common/types';
import { IConfigurationService } from '../../../common/types';
import { Deferred } from '../../../common/utils/async';
import { traceError, traceInfo, traceVerbose } from '../../../logging';
import { ExecutionTestPayload, ITestExecutionAdapter, ITestResultResolver } from '../common/types';
Expand All @@ -25,7 +25,6 @@ import { getEnvironment, runInBackground, useEnvExtension } from '../../../envEx
export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
constructor(
public configSettings: IConfigurationService,
private readonly outputChannel: ITestOutputChannel,
private readonly resultResolver?: ITestResultResolver,
private readonly envVarsService?: IEnvironmentVariablesProvider,
) {}
Expand Down Expand Up @@ -146,7 +145,6 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
const spawnOptions: SpawnOptions = {
cwd,
throwOnStdErr: true,
outputChannel: this.outputChannel,
env: mutableEnv,
token: runInstance?.token,
};
Expand Down Expand Up @@ -194,15 +192,12 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
proc.stdout.on('data', (data) => {
const out = utils.fixLogLinesNoTrailing(data.toString());
runInstance?.appendOutput(out);
this.outputChannel?.append(out);
});
proc.stderr.on('data', (data) => {
const out = utils.fixLogLinesNoTrailing(data.toString());
runInstance?.appendOutput(out);
this.outputChannel?.append(out);
});
proc.onExit((code, signal) => {
this.outputChannel?.append(utils.MESSAGE_ON_TESTING_OUTPUT_MOVE);
if (code !== 0) {
traceError(
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`,
Expand Down Expand Up @@ -240,19 +235,15 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {

// Take all output from the subprocess and add it to the test output channel. This will be the pytest output.
// Displays output to user and ensure the subprocess doesn't run into buffer overflow.
// TODO: after a release, remove run output from the "Python Test Log" channel and send it to the "Test Result" channel instead.
result?.proc?.stdout?.on('data', (data) => {
const out = utils.fixLogLinesNoTrailing(data.toString());
runInstance?.appendOutput(out);
this.outputChannel?.append(out);
});
result?.proc?.stderr?.on('data', (data) => {
const out = utils.fixLogLinesNoTrailing(data.toString());
runInstance?.appendOutput(out);
this.outputChannel?.append(out);
});
result?.proc?.on('exit', (code, signal) => {
this.outputChannel?.append(utils.MESSAGE_ON_TESTING_OUTPUT_MOVE);
if (code !== 0) {
traceError(
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`,
Expand Down
20 changes: 2 additions & 18 deletions src/client/testing/testController/unittest/testDiscoveryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'path';
import { CancellationTokenSource, Uri } from 'vscode';
import { CancellationToken } from 'vscode-jsonrpc';
import { ChildProcess } from 'child_process';
import { IConfigurationService, ITestOutputChannel } from '../../../common/types';
import { IConfigurationService } from '../../../common/types';
import { EXTENSION_ROOT_DIR } from '../../../constants';
import {
DiscoveredTestPayload,
Expand All @@ -22,12 +22,7 @@ import {
IPythonExecutionFactory,
SpawnOptions,
} from '../../../common/process/types';
import {
MESSAGE_ON_TESTING_OUTPUT_MOVE,
createDiscoveryErrorPayload,
fixLogLinesNoTrailing,
startDiscoveryNamedPipe,
} from '../common/utils';
import { createDiscoveryErrorPayload, fixLogLinesNoTrailing, startDiscoveryNamedPipe } from '../common/utils';
import { traceError, traceInfo, traceLog, traceVerbose } from '../../../logging';
import { getEnvironment, runInBackground, useEnvExtension } from '../../../envExt/api.internal';

Expand All @@ -37,7 +32,6 @@ import { getEnvironment, runInBackground, useEnvExtension } from '../../../envEx
export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
constructor(
public configSettings: IConfigurationService,
private readonly outputChannel: ITestOutputChannel,
private readonly resultResolver?: ITestResultResolver,
private readonly envVarsService?: IEnvironmentVariablesProvider,
) {}
Expand Down Expand Up @@ -79,7 +73,6 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
workspaceFolder: uri,
command,
cwd,
outChannel: this.outputChannel,
token,
};

Expand Down Expand Up @@ -128,15 +121,12 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
proc.stdout.on('data', (data) => {
const out = fixLogLinesNoTrailing(data.toString());
traceInfo(out);
this.outputChannel?.append(out);
});
proc.stderr.on('data', (data) => {
const out = fixLogLinesNoTrailing(data.toString());
traceError(out);
this.outputChannel?.append(out);
});
proc.onExit((code, signal) => {
this.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE);
if (code !== 0) {
traceError(
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`,
Expand All @@ -155,7 +145,6 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
token: options.token,
cwd: options.cwd,
throwOnStdErr: true,
outputChannel: options.outChannel,
env: mutableEnv,
};

Expand Down Expand Up @@ -187,22 +176,17 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
resultProc = result?.proc;

// Displays output to user and ensure the subprocess doesn't run into buffer overflow.
// TODO: after a release, remove discovery output from the "Python Test Log" channel and send it to the "Python" channel instead.
// TODO: after a release, remove run output from the "Python Test Log" channel and send it to the "Test Result" channel instead.
result?.proc?.stdout?.on('data', (data) => {
const out = fixLogLinesNoTrailing(data.toString());
spawnOptions?.outputChannel?.append(`${out}`);
traceInfo(out);
});
result?.proc?.stderr?.on('data', (data) => {
const out = fixLogLinesNoTrailing(data.toString());
spawnOptions?.outputChannel?.append(`${out}`);
traceError(out);
});

result?.proc?.on('exit', (code, signal) => {
// if the child has testIds then this is a run request
spawnOptions?.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE);

if (code !== 0) {
// This occurs when we are running discovery
Expand Down
Loading