diff --git a/src/client/testing/testController/common/types.ts b/src/client/testing/testController/common/types.ts index 579c11d5ef25..e9eebb4c44d2 100644 --- a/src/client/testing/testController/common/types.ts +++ b/src/client/testing/testController/common/types.ts @@ -12,6 +12,7 @@ import { Uri, WorkspaceFolder, } from 'vscode'; +// ** import { IPythonExecutionFactory } from '../../../common/process/types'; import { TestDiscoveryOptions } from '../../common/types'; export type TestRunInstanceOptions = TestRunOptions & { @@ -179,12 +180,19 @@ export interface ITestServer { export interface ITestDiscoveryAdapter { // ** Uncomment second line and comment out first line to use the new discovery method. discoverTests(uri: Uri): Promise; - // discoverTests(uri: Uri, executionFactory: IPythonExecutionFactory): Promise + // discoverTests(uri: Uri, executionFactory: IPythonExecutionFactory): Promise; } // interface for execution/runner adapter export interface ITestExecutionAdapter { + // ** Uncomment second line and comment out first line to use the new execution method. runTests(uri: Uri, testIds: string[], debugBool?: boolean): Promise; + // runTests( + // uri: Uri, + // testIds: string[], + // debugBool?: boolean, + // executionFactory?: IPythonExecutionFactory, + // ): Promise; } // Same types as in pythonFiles/unittestadapter/utils.py diff --git a/src/client/testing/testController/controller.ts b/src/client/testing/testController/controller.ts index 8cba671277d0..b2be2d9c3054 100644 --- a/src/client/testing/testController/controller.ts +++ b/src/client/testing/testController/controller.ts @@ -162,7 +162,7 @@ export class PythonTestController implements ITestController, IExtensionSingleAc executionAdapter = new UnittestTestExecutionAdapter(this.pythonTestServer, this.configSettings); testProvider = UNITTEST_PROVIDER; } else { - discoveryAdapter = new PytestTestDiscoveryAdapter(this.pythonTestServer, { ...this.configSettings }); + discoveryAdapter = new PytestTestDiscoveryAdapter(this.pythonTestServer, this.configSettings); executionAdapter = new PytestTestExecutionAdapter(this.pythonTestServer, this.configSettings); testProvider = PYTEST_PROVIDER; } @@ -372,6 +372,20 @@ export class PythonTestController implements ITestController, IExtensionSingleAc tool: 'pytest', debugging: request.profile?.kind === TestRunProfileKind.Debug, }); + // ** new execution runner/adapter + // const testAdapter = + // this.testAdapters.get(workspace.uri) || + // (this.testAdapters.values().next().value as WorkspaceTestAdapter); + // return testAdapter.executeTests( + // this.testController, + // runInstance, + // testItems, + // token, + // request.profile?.kind === TestRunProfileKind.Debug, + // this.pythonExecFactory, + // ); + + // below is old way of running pytest execution return this.pytest.runTests( { includes: testItems, @@ -402,7 +416,6 @@ export class PythonTestController implements ITestController, IExtensionSingleAc // ); // below is old way of running unittest execution - return this.unittest.runTests( { includes: testItems, diff --git a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts index 35d62c50e774..eaabb57691d0 100644 --- a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts +++ b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts @@ -1,22 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import * as path from 'path'; import { Uri } from 'vscode'; import { IConfigurationService } from '../../../common/types'; import { createDeferred, Deferred } from '../../../common/utils/async'; -import { EXTENSION_ROOT_DIR } from '../../../constants'; -import { - DataReceivedEvent, - ExecutionTestPayload, - ITestExecutionAdapter, - ITestServer, - TestCommandOptions, - TestExecutionCommand, -} from '../common/types'; +import { traceVerbose } from '../../../logging'; +import { DataReceivedEvent, ExecutionTestPayload, ITestExecutionAdapter, ITestServer } from '../common/types'; /** - * Wrapper Class for unittest test execution. This is where we call `runTestCommand`? + * Wrapper Class for pytest test execution. This is where we call `runTestCommand`? */ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { @@ -37,37 +29,69 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { } } - public async runTests(uri: Uri, testIds: string[], debugBool?: boolean): Promise { - if (!this.deferred) { - const settings = this.configSettings.getSettings(uri); - const { unittestArgs } = settings.testing; + // ** Old version of discover tests. + async runTests(uri: Uri, testIds: string[], debugBool?: boolean): Promise { + traceVerbose(uri, testIds, debugBool); + this.deferred = createDeferred(); + return this.deferred.promise; + } - const command = buildExecutionCommand(unittestArgs); - this.cwd = uri.fsPath; + // public async runTests( + // uri: Uri, + // testIds: string[], + // debugBool?: boolean, + // executionFactory?: IPythonExecutionFactory, + // ): Promise { + // if (!this.deferred) { + // this.deferred = createDeferred(); + // const relativePathToPytest = 'pythonFiles'; + // const fullPluginPath = path.join(EXTENSION_ROOT_DIR, relativePathToPytest); + // this.configSettings.isTestExecution(); + // const uuid = this.testServer.createUUID(uri.fsPath); + // const settings = this.configSettings.getSettings(uri); + // const { pytestArgs } = settings.testing; - const options: TestCommandOptions = { - workspaceFolder: uri, - command, - cwd: this.cwd, - debugBool, - testIds, - }; + // const pythonPathParts: string[] = process.env.PYTHONPATH?.split(path.delimiter) ?? []; + // const pythonPathCommand = [fullPluginPath, ...pythonPathParts].join(path.delimiter); - this.deferred = createDeferred(); + // const spawnOptions: SpawnOptions = { + // cwd: uri.fsPath, + // throwOnStdErr: true, + // extraVariables: { + // PYTHONPATH: pythonPathCommand, + // TEST_UUID: uuid.toString(), + // TEST_PORT: this.testServer.getPort().toString(), + // }, + // }; - // send test command to server - // server fire onDataReceived event once it gets response - this.testServer.sendCommand(options); - } - return this.deferred.promise; - } -} + // // Create the Python environment in which to execute the command. + // const creationOptions: ExecutionFactoryCreateWithEnvironmentOptions = { + // allowEnvironmentFetchExceptions: false, + // resource: uri, + // }; + // // need to check what will happen in the exec service is NOT defined and is null + // const execService = await executionFactory?.createActivatedEnvironment(creationOptions); + + // const testIdsString = testIds.join(' '); + // console.debug('what to do with debug bool?', debugBool); + // try { + // execService?.exec( + // ['-m', 'pytest', '-p', 'vscode_pytest', testIdsString].concat(pytestArgs), + // spawnOptions, + // ); + // } catch (ex) { + // console.error(ex); + // } + // } + // return this.deferred.promise; + // } + // } -function buildExecutionCommand(args: string[]): TestExecutionCommand { - const executionScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'unittestadapter', 'execution.py'); + // function buildExecutionCommand(args: string[]): TestExecutionCommand { + // const executionScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'unittestadapter', 'execution.py'); - return { - script: executionScript, - args: ['--udiscovery', ...args], - }; + // return { + // script: executionScript, + // args: ['--udiscovery', ...args], + // }; } diff --git a/src/client/testing/testController/workspaceTestAdapter.ts b/src/client/testing/testController/workspaceTestAdapter.ts index 32bc0d5c29ef..dc9c65c431fd 100644 --- a/src/client/testing/testController/workspaceTestAdapter.ts +++ b/src/client/testing/testController/workspaceTestAdapter.ts @@ -68,6 +68,7 @@ export class WorkspaceTestAdapter { this.vsIdToRunId = new Map(); } + // ** add executionFactory?: IPythonExecutionFactory, to the parameters public async executeTests( testController: TestController, runInstance: TestRun, @@ -100,8 +101,18 @@ export class WorkspaceTestAdapter { } }); - // need to get the testItems runIds so that we can pass in here. + // ** First line is old way, section with if statement below is new way. rawTestExecData = await this.executionAdapter.runTests(this.workspaceUri, testCaseIds, debugBool); + // if (executionFactory !== undefined) { + // rawTestExecData = await this.executionAdapter.runTests( + // this.workspaceUri, + // testCaseIds, + // debugBool, + // executionFactory, + // ); + // } else { + // traceVerbose('executionFactory is undefined'); + // } deferred.resolve(); } catch (ex) { // handle token and telemetry here