Skip to content

Commit 3e750ed

Browse files
committed
discovery refactoring
1 parent 9c88db8 commit 3e750ed

File tree

6 files changed

+19
-23
lines changed

6 files changed

+19
-23
lines changed

src/client/testing/testController/common/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@ export interface ITestResultResolver {
155155
_resolveCoverage(payload: CoveragePayload, runInstance: TestRun): void;
156156
}
157157
export interface ITestDiscoveryAdapter {
158-
// ** first line old method signature, second line new method signature
159-
discoverTests(uri: Uri): Promise<void>;
160158
discoverTests(
161159
uri: Uri,
162-
executionFactory?: IPythonExecutionFactory,
160+
executionFactory: IPythonExecutionFactory,
163161
token?: CancellationToken,
164162
interpreter?: PythonEnvironment,
165163
): Promise<void>;

src/client/testing/testController/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
276276
}
277277
await testAdapter.discoverTests(
278278
this.testController,
279-
this.refreshCancellation.token,
280279
this.pythonExecFactory,
280+
this.refreshCancellation.token,
281281
await this.interpreterService.getActiveInterpreter(workspace.uri),
282282
);
283283
} else {
@@ -302,8 +302,8 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
302302
}
303303
await testAdapter.discoverTests(
304304
this.testController,
305-
this.refreshCancellation.token,
306305
this.pythonExecFactory,
306+
this.refreshCancellation.token,
307307
await this.interpreterService.getActiveInterpreter(workspace.uri),
308308
);
309309
} else {

src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
3838

3939
async discoverTests(
4040
uri: Uri,
41-
executionFactory?: IPythonExecutionFactory,
41+
executionFactory: IPythonExecutionFactory,
4242
token?: CancellationToken,
4343
interpreter?: PythonEnvironment,
4444
): Promise<void> {
@@ -69,7 +69,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
6969
uri: Uri,
7070
discoveryPipeName: string,
7171
cSource: CancellationTokenSource,
72-
executionFactory?: IPythonExecutionFactory,
72+
executionFactory: IPythonExecutionFactory,
7373
interpreter?: PythonEnvironment,
7474
token?: CancellationToken,
7575
): Promise<void> {
@@ -170,7 +170,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
170170
resource: uri,
171171
interpreter,
172172
};
173-
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
173+
const execService = await executionFactory.createActivatedEnvironment(creationOptions);
174174

175175
const execInfo = await execService?.getExecutablePath();
176176
traceVerbose(`Executable path for pytest discovery: ${execInfo}.`);

src/client/testing/testController/unittest/testDiscoveryAdapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
3838

3939
public async discoverTests(
4040
uri: Uri,
41-
executionFactory?: IPythonExecutionFactory,
41+
executionFactory: IPythonExecutionFactory,
4242
token?: CancellationToken,
4343
): Promise<void> {
4444
const settings = this.configSettings.getSettings(uri);
@@ -89,7 +89,7 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
8989
testRunPipeName: string,
9090
cwd: string,
9191
cSource: CancellationTokenSource,
92-
executionFactory?: IPythonExecutionFactory,
92+
executionFactory: IPythonExecutionFactory,
9393
): Promise<void> {
9494
// get and edit env vars
9595
const mutableEnv = {
@@ -157,7 +157,7 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
157157
allowEnvironmentFetchExceptions: false,
158158
resource: options.workspaceFolder,
159159
};
160-
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
160+
const execService = await executionFactory.createActivatedEnvironment(creationOptions);
161161
const execInfo = await execService?.getExecutablePath();
162162
traceVerbose(`Executable path for unittest discovery: ${execInfo}.`);
163163

src/client/testing/testController/workspaceTestAdapter.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export class WorkspaceTestAdapter {
114114

115115
public async discoverTests(
116116
testController: TestController,
117+
executionFactory: IPythonExecutionFactory,
117118
token?: CancellationToken,
118-
executionFactory?: IPythonExecutionFactory,
119119
interpreter?: PythonEnvironment,
120120
): Promise<void> {
121121
sendTelemetryEvent(EventName.UNITTEST_DISCOVERING, undefined, { tool: this.testProvider });
@@ -130,12 +130,10 @@ export class WorkspaceTestAdapter {
130130
this.discovering = deferred;
131131

132132
try {
133-
// ** execution factory only defined for new rewrite way
134-
if (executionFactory !== undefined) {
135-
await this.discoveryAdapter.discoverTests(this.workspaceUri, executionFactory, token, interpreter);
136-
} else {
137-
await this.discoveryAdapter.discoverTests(this.workspaceUri);
133+
if (executionFactory === undefined) {
134+
throw new Error('Execution factory is required for test discovery');
138135
}
136+
await this.discoveryAdapter.discoverTests(this.workspaceUri, executionFactory, token, interpreter);
139137
deferred.resolve();
140138
} catch (ex) {
141139
sendTelemetryEvent(EventName.UNITTEST_DISCOVERY_DONE, undefined, { tool: this.testProvider, failed: true });

src/test/testing/testController/workspaceTestAdapter.unit.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ suite('Workspace test adapter', () => {
147147
const testProvider = 'unittest';
148148

149149
execFactory = typemoq.Mock.ofType<IPythonExecutionFactory>();
150-
await workspaceTestAdapter.discoverTests(testController, undefined, execFactory.object);
150+
await workspaceTestAdapter.discoverTests(testController, execFactory.object);
151151

152152
sinon.assert.calledWithMatch(createErrorTestItemStub, sinon.match.any, sinon.match.any);
153153
sinon.assert.calledWithMatch(buildErrorNodeOptionsStub, uriFoo, sinon.match.any, testProvider);
@@ -166,7 +166,7 @@ suite('Workspace test adapter', () => {
166166
stubResultResolver,
167167
);
168168

169-
await workspaceTestAdapter.discoverTests(testController, undefined, execFactory.object);
169+
await workspaceTestAdapter.discoverTests(testController, execFactory.object);
170170

171171
sinon.assert.calledOnce(discoverTestsStub);
172172
});
@@ -193,8 +193,8 @@ suite('Workspace test adapter', () => {
193193
);
194194

195195
// Try running discovery twice
196-
const one = workspaceTestAdapter.discoverTests(testController);
197-
const two = workspaceTestAdapter.discoverTests(testController);
196+
const one = workspaceTestAdapter.discoverTests(testController, execFactory.object);
197+
const two = workspaceTestAdapter.discoverTests(testController, execFactory.object);
198198

199199
Promise.all([one, two]);
200200

@@ -215,7 +215,7 @@ suite('Workspace test adapter', () => {
215215
stubResultResolver,
216216
);
217217

218-
await workspaceTestAdapter.discoverTests(testController, undefined, execFactory.object);
218+
await workspaceTestAdapter.discoverTests(testController, execFactory.object);
219219

220220
sinon.assert.calledWith(sendTelemetryStub, EventName.UNITTEST_DISCOVERY_DONE);
221221
assert.strictEqual(telemetryEvent.length, 2);
@@ -238,7 +238,7 @@ suite('Workspace test adapter', () => {
238238
stubResultResolver,
239239
);
240240

241-
await workspaceTestAdapter.discoverTests(testController);
241+
await workspaceTestAdapter.discoverTests(testController, execFactory.object);
242242

243243
sinon.assert.calledWith(sendTelemetryStub, EventName.UNITTEST_DISCOVERY_DONE);
244244
assert.strictEqual(telemetryEvent.length, 2);

0 commit comments

Comments
 (0)