Skip to content

Commit

Permalink
error msg for adapter unalignment issue (#24385)
Browse files Browse the repository at this point in the history
resolves #23234 as it
surfaces readable error
  • Loading branch information
eleanorjboyd authored Nov 4, 2024
1 parent 3e7e0d2 commit 5d56379
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
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;
}
}

0 comments on commit 5d56379

Please sign in to comment.