Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/client/common/process/pythonExecutionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
pythonPath: options.interpreter ? options.interpreter.path : undefined,
});
}

const pythonPath = options.interpreter
? options.interpreter.path
: this.configService.getSettings(options.resource).pythonPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
hasSymlinkParent,
} from '../common/utils';
import { IEnvironmentVariablesProvider } from '../../../common/variables/types';
import { IInterpreterService } from '../../../interpreter/contracts';

/**
* Wrapper class for unittest test discovery. This is where we call `runTestCommand`. #this seems incorrectly copied
Expand All @@ -34,6 +35,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
private readonly outputChannel: ITestOutputChannel,
private readonly resultResolver?: ITestResultResolver,
private readonly envVarsService?: IEnvironmentVariablesProvider,
private readonly interpreterService?: IInterpreterService,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to avoid dependency injection here - bit difficult since there are listener and event handlers like onDidChangeInterpreters attached.

We could also partially avoid using configService for: path = this.configService.getSettings(resource).pythonPath;

  • Rather just make an API to get getting with resource without configService would be cleaner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to plumb the service through all layers. We can just pass the interpreter into the various layers.

) {}

async discoverTests(uri: Uri, executionFactory?: IPythonExecutionFactory): Promise<DiscoveredTestPayload> {
Expand Down Expand Up @@ -102,11 +104,15 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
env: mutableEnv,
};

const interpreter = await this.interpreterService?.getActiveInterpreter();

// Create the Python environment in which to execute the command.
const creationOptions: ExecutionFactoryCreateWithEnvironmentOptions = {
allowEnvironmentFetchExceptions: false,
resource: uri,
interpreter,
};

const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
// delete UUID following entire discovery finishing.
const execArgs = ['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import { PYTEST_PROVIDER } from '../../common/constants';
import { EXTENSION_ROOT_DIR } from '../../../common/constants';
import * as utils from '../common/utils';
import { IEnvironmentVariablesProvider } from '../../../common/variables/types';
import { IInterpreterService } from '../../../interpreter/contracts';

export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
constructor(
public configSettings: IConfigurationService,
private readonly outputChannel: ITestOutputChannel,
private readonly resultResolver?: ITestResultResolver,
private readonly envVarsService?: IEnvironmentVariablesProvider,
private readonly interpreterService?: IInterpreterService,
) {}

async runTests(
Expand Down Expand Up @@ -131,10 +133,13 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
}
const debugBool = profileKind && profileKind === TestRunProfileKind.Debug;

const interpreter = await this.interpreterService?.getActiveInterpreter();

// Create the Python environment in which to execute the command.
const creationOptions: ExecutionFactoryCreateWithEnvironmentOptions = {
allowEnvironmentFetchExceptions: false,
resource: uri,
interpreter,
};
// need to check what will happen in the exec service is NOT defined and is null
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
Expand Down
9 changes: 8 additions & 1 deletion src/test/testing/common/testingAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import { TestProvider } from '../../../client/testing/types';
import { PYTEST_PROVIDER, UNITTEST_PROVIDER } from '../../../client/testing/common/constants';
import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types';
import { createTypeMoq } from '../../mocks/helper';
import { IInterpreterService } from '../../../client/interpreter/contracts';

suite('End to End Tests: test adapters', () => {
let interpreterService: IInterpreterService;
let resultResolver: ITestResultResolver;
let pythonExecFactory: IPythonExecutionFactory;
let configService: IConfigurationService;
Expand Down Expand Up @@ -109,7 +111,7 @@ suite('End to End Tests: test adapters', () => {
pythonExecFactory = serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory);
testController = serviceContainer.get<TestController>(ITestController);
envVarsService = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);

interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
// create objects that were not injected

testOutputChannel = createTypeMoq<ITestOutputChannel>();
Expand Down Expand Up @@ -271,6 +273,7 @@ suite('End to End Tests: test adapters', () => {
testOutputChannel.object,
resultResolver,
envVarsService,
interpreterService,
);

await discoveryAdapter.discoverTests(workspaceUri, pythonExecFactory).finally(() => {
Expand Down Expand Up @@ -326,6 +329,7 @@ suite('End to End Tests: test adapters', () => {
testOutputChannel.object,
resultResolver,
envVarsService,
interpreterService,
);
configService.getSettings(workspaceUri).testing.pytestArgs = [];

Expand Down Expand Up @@ -415,6 +419,7 @@ suite('End to End Tests: test adapters', () => {
testOutputChannel.object,
resultResolver,
envVarsService,
interpreterService,
);
configService.getSettings(workspaceUri).testing.pytestArgs = [];

Expand Down Expand Up @@ -491,6 +496,7 @@ suite('End to End Tests: test adapters', () => {
testOutputChannel.object,
resultResolver,
envVarsService,
interpreterService,
);

// set workspace to test workspace folder
Expand Down Expand Up @@ -1038,6 +1044,7 @@ suite('End to End Tests: test adapters', () => {
testOutputChannel.object,
resultResolver,
envVarsService,
interpreterService,
);

// set workspace to test workspace folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ suite('pytest test discovery adapter', () => {
execService = typeMoq.Mock.ofType<IPythonExecutionService>();
execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
outputChannel = typeMoq.Mock.ofType<ITestOutputChannel>();

const output = new Observable<Output<string>>(() => {
/* no op */
});
Expand Down
Loading