Skip to content

Commit a6a6f50

Browse files
authored
Inactive pytest run command (#20653)
Here the new flow is created but kept inactive for the pytest execution
1 parent 2202fbe commit a6a6f50

File tree

4 files changed

+98
-42
lines changed

4 files changed

+98
-42
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
Uri,
1313
WorkspaceFolder,
1414
} from 'vscode';
15+
// ** import { IPythonExecutionFactory } from '../../../common/process/types';
1516
import { TestDiscoveryOptions } from '../../common/types';
1617

1718
export type TestRunInstanceOptions = TestRunOptions & {
@@ -179,12 +180,19 @@ export interface ITestServer {
179180
export interface ITestDiscoveryAdapter {
180181
// ** Uncomment second line and comment out first line to use the new discovery method.
181182
discoverTests(uri: Uri): Promise<DiscoveredTestPayload>;
182-
// discoverTests(uri: Uri, executionFactory: IPythonExecutionFactory): Promise<DiscoveredTestPayload>
183+
// discoverTests(uri: Uri, executionFactory: IPythonExecutionFactory): Promise<DiscoveredTestPayload>;
183184
}
184185

185186
// interface for execution/runner adapter
186187
export interface ITestExecutionAdapter {
188+
// ** Uncomment second line and comment out first line to use the new execution method.
187189
runTests(uri: Uri, testIds: string[], debugBool?: boolean): Promise<ExecutionTestPayload>;
190+
// runTests(
191+
// uri: Uri,
192+
// testIds: string[],
193+
// debugBool?: boolean,
194+
// executionFactory?: IPythonExecutionFactory,
195+
// ): Promise<ExecutionTestPayload>;
188196
}
189197

190198
// Same types as in pythonFiles/unittestadapter/utils.py

src/client/testing/testController/controller.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
162162
executionAdapter = new UnittestTestExecutionAdapter(this.pythonTestServer, this.configSettings);
163163
testProvider = UNITTEST_PROVIDER;
164164
} else {
165-
discoveryAdapter = new PytestTestDiscoveryAdapter(this.pythonTestServer, { ...this.configSettings });
165+
discoveryAdapter = new PytestTestDiscoveryAdapter(this.pythonTestServer, this.configSettings);
166166
executionAdapter = new PytestTestExecutionAdapter(this.pythonTestServer, this.configSettings);
167167
testProvider = PYTEST_PROVIDER;
168168
}
@@ -372,6 +372,20 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
372372
tool: 'pytest',
373373
debugging: request.profile?.kind === TestRunProfileKind.Debug,
374374
});
375+
// ** new execution runner/adapter
376+
// const testAdapter =
377+
// this.testAdapters.get(workspace.uri) ||
378+
// (this.testAdapters.values().next().value as WorkspaceTestAdapter);
379+
// return testAdapter.executeTests(
380+
// this.testController,
381+
// runInstance,
382+
// testItems,
383+
// token,
384+
// request.profile?.kind === TestRunProfileKind.Debug,
385+
// this.pythonExecFactory,
386+
// );
387+
388+
// below is old way of running pytest execution
375389
return this.pytest.runTests(
376390
{
377391
includes: testItems,
@@ -402,7 +416,6 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
402416
// );
403417

404418
// below is old way of running unittest execution
405-
406419
return this.unittest.runTests(
407420
{
408421
includes: testItems,
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import * as path from 'path';
54
import { Uri } from 'vscode';
65
import { IConfigurationService } from '../../../common/types';
76
import { createDeferred, Deferred } from '../../../common/utils/async';
8-
import { EXTENSION_ROOT_DIR } from '../../../constants';
9-
import {
10-
DataReceivedEvent,
11-
ExecutionTestPayload,
12-
ITestExecutionAdapter,
13-
ITestServer,
14-
TestCommandOptions,
15-
TestExecutionCommand,
16-
} from '../common/types';
7+
import { traceVerbose } from '../../../logging';
8+
import { DataReceivedEvent, ExecutionTestPayload, ITestExecutionAdapter, ITestServer } from '../common/types';
179

1810
/**
19-
* Wrapper Class for unittest test execution. This is where we call `runTestCommand`?
11+
* Wrapper Class for pytest test execution. This is where we call `runTestCommand`?
2012
*/
2113

2214
export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
@@ -37,37 +29,69 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
3729
}
3830
}
3931

40-
public async runTests(uri: Uri, testIds: string[], debugBool?: boolean): Promise<ExecutionTestPayload> {
41-
if (!this.deferred) {
42-
const settings = this.configSettings.getSettings(uri);
43-
const { unittestArgs } = settings.testing;
32+
// ** Old version of discover tests.
33+
async runTests(uri: Uri, testIds: string[], debugBool?: boolean): Promise<ExecutionTestPayload> {
34+
traceVerbose(uri, testIds, debugBool);
35+
this.deferred = createDeferred<ExecutionTestPayload>();
36+
return this.deferred.promise;
37+
}
4438

45-
const command = buildExecutionCommand(unittestArgs);
46-
this.cwd = uri.fsPath;
39+
// public async runTests(
40+
// uri: Uri,
41+
// testIds: string[],
42+
// debugBool?: boolean,
43+
// executionFactory?: IPythonExecutionFactory,
44+
// ): Promise<ExecutionTestPayload> {
45+
// if (!this.deferred) {
46+
// this.deferred = createDeferred<ExecutionTestPayload>();
47+
// const relativePathToPytest = 'pythonFiles';
48+
// const fullPluginPath = path.join(EXTENSION_ROOT_DIR, relativePathToPytest);
49+
// this.configSettings.isTestExecution();
50+
// const uuid = this.testServer.createUUID(uri.fsPath);
51+
// const settings = this.configSettings.getSettings(uri);
52+
// const { pytestArgs } = settings.testing;
4753

48-
const options: TestCommandOptions = {
49-
workspaceFolder: uri,
50-
command,
51-
cwd: this.cwd,
52-
debugBool,
53-
testIds,
54-
};
54+
// const pythonPathParts: string[] = process.env.PYTHONPATH?.split(path.delimiter) ?? [];
55+
// const pythonPathCommand = [fullPluginPath, ...pythonPathParts].join(path.delimiter);
5556

56-
this.deferred = createDeferred<ExecutionTestPayload>();
57+
// const spawnOptions: SpawnOptions = {
58+
// cwd: uri.fsPath,
59+
// throwOnStdErr: true,
60+
// extraVariables: {
61+
// PYTHONPATH: pythonPathCommand,
62+
// TEST_UUID: uuid.toString(),
63+
// TEST_PORT: this.testServer.getPort().toString(),
64+
// },
65+
// };
5766

58-
// send test command to server
59-
// server fire onDataReceived event once it gets response
60-
this.testServer.sendCommand(options);
61-
}
62-
return this.deferred.promise;
63-
}
64-
}
67+
// // Create the Python environment in which to execute the command.
68+
// const creationOptions: ExecutionFactoryCreateWithEnvironmentOptions = {
69+
// allowEnvironmentFetchExceptions: false,
70+
// resource: uri,
71+
// };
72+
// // need to check what will happen in the exec service is NOT defined and is null
73+
// const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
74+
75+
// const testIdsString = testIds.join(' ');
76+
// console.debug('what to do with debug bool?', debugBool);
77+
// try {
78+
// execService?.exec(
79+
// ['-m', 'pytest', '-p', 'vscode_pytest', testIdsString].concat(pytestArgs),
80+
// spawnOptions,
81+
// );
82+
// } catch (ex) {
83+
// console.error(ex);
84+
// }
85+
// }
86+
// return this.deferred.promise;
87+
// }
88+
// }
6589

66-
function buildExecutionCommand(args: string[]): TestExecutionCommand {
67-
const executionScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'unittestadapter', 'execution.py');
90+
// function buildExecutionCommand(args: string[]): TestExecutionCommand {
91+
// const executionScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'unittestadapter', 'execution.py');
6892

69-
return {
70-
script: executionScript,
71-
args: ['--udiscovery', ...args],
72-
};
93+
// return {
94+
// script: executionScript,
95+
// args: ['--udiscovery', ...args],
96+
// };
7397
}

src/client/testing/testController/workspaceTestAdapter.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class WorkspaceTestAdapter {
6868
this.vsIdToRunId = new Map<string, string>();
6969
}
7070

71+
// ** add executionFactory?: IPythonExecutionFactory, to the parameters
7172
public async executeTests(
7273
testController: TestController,
7374
runInstance: TestRun,
@@ -100,8 +101,18 @@ export class WorkspaceTestAdapter {
100101
}
101102
});
102103

103-
// need to get the testItems runIds so that we can pass in here.
104+
// ** First line is old way, section with if statement below is new way.
104105
rawTestExecData = await this.executionAdapter.runTests(this.workspaceUri, testCaseIds, debugBool);
106+
// if (executionFactory !== undefined) {
107+
// rawTestExecData = await this.executionAdapter.runTests(
108+
// this.workspaceUri,
109+
// testCaseIds,
110+
// debugBool,
111+
// executionFactory,
112+
// );
113+
// } else {
114+
// traceVerbose('executionFactory is undefined');
115+
// }
105116
deferred.resolve();
106117
} catch (ex) {
107118
// handle token and telemetry here

0 commit comments

Comments
 (0)