Skip to content

error msg for adapter unalignment issue #24385

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 1 commit into from
Nov 4, 2024
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
37 changes: 35 additions & 2 deletions src/client/testing/testController/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
TextDocument,
FileCoverageDetail,
TestRun,
MarkdownString,
} from 'vscode';
import { IExtensionSingleActivationService } from '../../activation/types';
import { ICommandManager, IWorkspaceService } from '../../common/application/types';
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
}
9 changes: 9 additions & 0 deletions src/client/testing/testController/workspaceTestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading