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 3 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
12 changes: 6 additions & 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, ILogOutputChannel, 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,7 @@ 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(ILogOutputChannel) private readonly logOutputChannel: ILogOutputChannel,
@inject(IEnvironmentVariablesProvider) private readonly envVarsService: IEnvironmentVariablesProvider,
) {
this.refreshCancellation = new CancellationTokenSource();
Expand Down Expand Up @@ -176,13 +176,13 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
resultResolver = new PythonResultResolver(this.testController, testProvider, workspace.uri);
discoveryAdapter = new UnittestTestDiscoveryAdapter(
this.configSettings,
this.testOutputChannel,
this.logOutputChannel,
resultResolver,
this.envVarsService,
);
executionAdapter = new UnittestTestExecutionAdapter(
this.configSettings,
this.testOutputChannel,
this.logOutputChannel,
resultResolver,
this.envVarsService,
);
Expand All @@ -191,13 +191,13 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
resultResolver = new PythonResultResolver(this.testController, testProvider, workspace.uri);
discoveryAdapter = new PytestTestDiscoveryAdapter(
this.configSettings,
this.testOutputChannel,
this.logOutputChannel,
resultResolver,
this.envVarsService,
);
executionAdapter = new PytestTestExecutionAdapter(
this.configSettings,
this.testOutputChannel,
this.logOutputChannel,
resultResolver,
this.envVarsService,
);
Expand Down
12 changes: 2 additions & 10 deletions src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts
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, ILogOutputChannel } 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,7 @@ import { useEnvExtension, getEnvironment, runInBackground } from '../../../envEx
export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
constructor(
public configSettings: IConfigurationService,
private readonly outputChannel: ITestOutputChannel,
private readonly outputChannel: ILogOutputChannel,
private readonly resultResolver?: ITestResultResolver,
private readonly envVarsService?: IEnvironmentVariablesProvider,
) {}
Expand Down Expand Up @@ -138,15 +137,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 Down Expand Up @@ -200,20 +196,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, ILogOutputChannel } 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,7 @@ import { getEnvironment, runInBackground, useEnvExtension } from '../../../envEx
export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
constructor(
public configSettings: IConfigurationService,
private readonly outputChannel: ITestOutputChannel,
private readonly outputChannel: ILogOutputChannel,
private readonly resultResolver?: ITestResultResolver,
private readonly envVarsService?: IEnvironmentVariablesProvider,
) {}
Expand Down Expand Up @@ -194,15 +194,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 +237,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
21 changes: 4 additions & 17 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, ILogOutputChannel } 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,7 @@ import { getEnvironment, runInBackground, useEnvExtension } from '../../../envEx
export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
constructor(
public configSettings: IConfigurationService,
private readonly outputChannel: ITestOutputChannel,
private readonly logOutputChannel: ILogOutputChannel,
private readonly resultResolver?: ITestResultResolver,
private readonly envVarsService?: IEnvironmentVariablesProvider,
) {}
Expand Down Expand Up @@ -79,7 +74,7 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
workspaceFolder: uri,
command,
cwd,
outChannel: this.outputChannel,
outChannel: this.logOutputChannel,
Copy link
Member Author

@eleanorjboyd eleanorjboyd Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have replaced ITestOutputChannel with ILogOutputChannel and still passing it through the the adapters to then add it to the spawn options here. Want to confirm this is necessary since I thought this output channel was used by spawn but not exactly sure how to confirm. @karthiknadig

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks fine. I am not really sure if this is even used internally anymore. But, need to follow the references here to understand better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for recording purposes- Karthik and I looked into execObservable and found no usage of the output channel and so we it entirely from the adapter

token,
};

Expand Down Expand Up @@ -128,15 +123,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 Down Expand Up @@ -187,22 +179,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
Loading