Skip to content

Commit

Permalink
add correct retrieval of workspace adapter for test discovery in mult…
Browse files Browse the repository at this point in the history
…iroot context (#22246)

fixes: #22218
  • Loading branch information
eleanorjboyd authored Oct 17, 2023
1 parent 4caa207 commit 01c7665
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/client/testing/testController/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,27 +269,42 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
if (settings.testing.pytestEnabled) {
if (pythonTestAdapterRewriteEnabled(this.serviceContainer)) {
traceInfo(`Running discovery for pytest using the new test adapter.`);
const testAdapter =
this.testAdapters.get(uri) || (this.testAdapters.values().next().value as WorkspaceTestAdapter);
testAdapter.discoverTests(
this.testController,
this.refreshCancellation.token,
this.pythonExecFactory,
);
if (workspace && workspace.uri) {
const testAdapter = this.testAdapters.get(workspace.uri);
if (testAdapter) {
testAdapter.discoverTests(
this.testController,
this.refreshCancellation.token,
this.pythonExecFactory,
);
} else {
traceError('Unable to find test adapter for workspace.');
}
} else {
traceError('Unable to find workspace for given file');
}
} else {
// else use OLD test discovery mechanism
await this.pytest.refreshTestData(this.testController, uri, this.refreshCancellation.token);
}
} else if (settings.testing.unittestEnabled) {
if (pythonTestAdapterRewriteEnabled(this.serviceContainer)) {
traceInfo(`Running discovery for unittest using the new test adapter.`);
const testAdapter =
this.testAdapters.get(uri) || (this.testAdapters.values().next().value as WorkspaceTestAdapter);
testAdapter.discoverTests(
this.testController,
this.refreshCancellation.token,
this.pythonExecFactory,
);
traceInfo(`Running discovery for pytest using the new test adapter.`);
if (workspace && workspace.uri) {
const testAdapter = this.testAdapters.get(workspace.uri);
if (testAdapter) {
testAdapter.discoverTests(
this.testController,
this.refreshCancellation.token,
this.pythonExecFactory,
);
} else {
traceError('Unable to find test adapter for workspace.');
}
} else {
traceError('Unable to find workspace for given file');
}
} else {
// else use OLD test discovery mechanism
await this.unittest.refreshTestData(this.testController, uri, this.refreshCancellation.token);
Expand Down

0 comments on commit 01c7665

Please sign in to comment.