error msg for adapter unalignment issue (#24385)

resolves https://github.com/microsoft/vscode-python/issues/23234 as it
surfaces readable error
This commit is contained in:
Eleanor Boyd 2024-11-04 13:36:13 -08:00 коммит произвёл GitHub
Родитель 3e7e0d244b
Коммит 5d563792a7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 44 добавлений и 2 удалений

Просмотреть файл

@ -18,6 +18,7 @@ import {
TextDocument,
FileCoverageDetail,
TestRun,
MarkdownString,
} from 'vscode';
import { IExtensionSingleActivationService } from '../../activation/types';
import { ICommandManager, IWorkspaceService } from '../../common/application/types';
@ -32,8 +33,8 @@ import { IEventNamePropertyMapping, sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { PYTEST_PROVIDER, UNITTEST_PROVIDER } from '../common/constants';
import { TestProvider } from '../types';
import { DebugTestTag, getNodeByUri, RunTestTag } from './common/testItemUtilities';
import { pythonTestAdapterRewriteEnabled } from './common/utils';
import { createErrorTestItem, DebugTestTag, getNodeByUri, RunTestTag } from './common/testItemUtilities';
import { buildErrorNodeOptions, pythonTestAdapterRewriteEnabled } from './common/utils';
import {
ITestController,
ITestDiscoveryAdapter,
@ -275,6 +276,16 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
if (workspace && workspace.uri) {
const testAdapter = this.testAdapters.get(workspace.uri);
if (testAdapter) {
const testProviderInAdapter = testAdapter.getTestProvider();
if (testProviderInAdapter !== 'pytest') {
traceError('Test provider in adapter is not pytest. Please reload window.');
this.surfaceErrorNode(
workspace.uri,
'Test provider types are not aligned, please reload your VS Code window.',
'pytest',
);
return Promise.resolve();
}
await testAdapter.discoverTests(
this.testController,
this.refreshCancellation.token,
@ -297,6 +308,16 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
if (workspace && workspace.uri) {
const testAdapter = this.testAdapters.get(workspace.uri);
if (testAdapter) {
const testProviderInAdapter = testAdapter.getTestProvider();
if (testProviderInAdapter !== 'unittest') {
traceError('Test provider in adapter is not unittest. Please reload window.');
this.surfaceErrorNode(
workspace.uri,
'Test provider types are not aligned, please reload your VS Code window.',
'unittest',
);
return Promise.resolve();
}
await testAdapter.discoverTests(
this.testController,
this.refreshCancellation.token,
@ -598,4 +619,16 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
this.triggerTypes.push(trigger);
}
}
private surfaceErrorNode(workspaceUri: Uri, message: string, testProvider: TestProvider): void {
let errorNode = this.testController.items.get(`DiscoveryError:${workspaceUri.fsPath}`);
if (errorNode === undefined) {
const options = buildErrorNodeOptions(workspaceUri, message, testProvider);
errorNode = createErrorTestItem(this.testController, options);
this.testController.items.add(errorNode);
}
const errorNodeLabel: MarkdownString = new MarkdownString(message);
errorNodeLabel.isTrusted = true;
errorNode.error = errorNodeLabel;
}
}

Просмотреть файл

@ -167,4 +167,13 @@ export class WorkspaceTestAdapter {
sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, undefined, { tool: this.testProvider, failed: false });
return Promise.resolve();
}
/**
* Retrieves the current test provider instance.
*
* @returns {TestProvider} The instance of the test provider.
*/
public getTestProvider(): TestProvider {
return this.testProvider;
}
}