Skip to content

Commit 7323bde

Browse files
committed
pass in correct interpreter for pytest
1 parent 83c2f67 commit 7323bde

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
hasSymlinkParent,
2525
} from '../common/utils';
2626
import { IEnvironmentVariablesProvider } from '../../../common/variables/types';
27+
import { IInterpreterService } from '../../../interpreter/contracts';
2728

2829
/**
2930
* Wrapper class for unittest test discovery. This is where we call `runTestCommand`. #this seems incorrectly copied
@@ -34,6 +35,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
3435
private readonly outputChannel: ITestOutputChannel,
3536
private readonly resultResolver?: ITestResultResolver,
3637
private readonly envVarsService?: IEnvironmentVariablesProvider,
38+
private readonly interpreterService?: IInterpreterService,
3739
) {}
3840

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

107+
const interpreter = await this.interpreterService?.getActiveInterpreter();
108+
105109
// Create the Python environment in which to execute the command.
106110
const creationOptions: ExecutionFactoryCreateWithEnvironmentOptions = {
107111
allowEnvironmentFetchExceptions: false,
108112
resource: uri,
113+
interpreter,
109114
};
115+
110116
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
111117
// delete UUID following entire discovery finishing.
112118
const execArgs = ['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ import { PYTEST_PROVIDER } from '../../common/constants';
2525
import { EXTENSION_ROOT_DIR } from '../../../common/constants';
2626
import * as utils from '../common/utils';
2727
import { IEnvironmentVariablesProvider } from '../../../common/variables/types';
28+
import { IInterpreterService } from '../../../interpreter/contracts';
2829

2930
export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
3031
constructor(
3132
public configSettings: IConfigurationService,
3233
private readonly outputChannel: ITestOutputChannel,
3334
private readonly resultResolver?: ITestResultResolver,
3435
private readonly envVarsService?: IEnvironmentVariablesProvider,
36+
private readonly interpreterService?: IInterpreterService,
3537
) {}
3638

3739
async runTests(
@@ -131,10 +133,13 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
131133
}
132134
const debugBool = profileKind && profileKind === TestRunProfileKind.Debug;
133135

136+
const interpreter = await this.interpreterService?.getActiveInterpreter();
137+
134138
// Create the Python environment in which to execute the command.
135139
const creationOptions: ExecutionFactoryCreateWithEnvironmentOptions = {
136140
allowEnvironmentFetchExceptions: false,
137141
resource: uri,
142+
interpreter,
138143
};
139144
// need to check what will happen in the exec service is NOT defined and is null
140145
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);

src/test/testing/common/testingAdapter.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import { TestProvider } from '../../../client/testing/types';
2222
import { PYTEST_PROVIDER, UNITTEST_PROVIDER } from '../../../client/testing/common/constants';
2323
import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types';
2424
import { createTypeMoq } from '../../mocks/helper';
25+
import { IInterpreterService } from '../../../client/interpreter/contracts';
2526

2627
suite('End to End Tests: test adapters', () => {
28+
let interpreterService: IInterpreterService;
2729
let resultResolver: ITestResultResolver;
2830
let pythonExecFactory: IPythonExecutionFactory;
2931
let configService: IConfigurationService;
@@ -109,7 +111,7 @@ suite('End to End Tests: test adapters', () => {
109111
pythonExecFactory = serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory);
110112
testController = serviceContainer.get<TestController>(ITestController);
111113
envVarsService = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
112-
114+
interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
113115
// create objects that were not injected
114116

115117
testOutputChannel = createTypeMoq<ITestOutputChannel>();
@@ -271,6 +273,7 @@ suite('End to End Tests: test adapters', () => {
271273
testOutputChannel.object,
272274
resultResolver,
273275
envVarsService,
276+
interpreterService,
274277
);
275278

276279
await discoveryAdapter.discoverTests(workspaceUri, pythonExecFactory).finally(() => {
@@ -326,6 +329,7 @@ suite('End to End Tests: test adapters', () => {
326329
testOutputChannel.object,
327330
resultResolver,
328331
envVarsService,
332+
interpreterService,
329333
);
330334
configService.getSettings(workspaceUri).testing.pytestArgs = [];
331335

@@ -415,6 +419,7 @@ suite('End to End Tests: test adapters', () => {
415419
testOutputChannel.object,
416420
resultResolver,
417421
envVarsService,
422+
interpreterService,
418423
);
419424
configService.getSettings(workspaceUri).testing.pytestArgs = [];
420425

@@ -491,6 +496,7 @@ suite('End to End Tests: test adapters', () => {
491496
testOutputChannel.object,
492497
resultResolver,
493498
envVarsService,
499+
interpreterService,
494500
);
495501

496502
// set workspace to test workspace folder
@@ -1038,6 +1044,7 @@ suite('End to End Tests: test adapters', () => {
10381044
testOutputChannel.object,
10391045
resultResolver,
10401046
envVarsService,
1047+
interpreterService,
10411048
);
10421049

10431050
// set workspace to test workspace folder

src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { EXTENSION_ROOT_DIR } from '../../../../client/constants';
2020
import { MockChildProcess } from '../../../mocks/mockChildProcess';
2121
import { Deferred, createDeferred } from '../../../../client/common/utils/async';
2222
import * as util from '../../../../client/testing/testController/common/utils';
23+
import { IInterpreterService } from '../../../../client/interpreter/contracts';
2324

2425
suite('pytest test discovery adapter', () => {
2526
let configService: IConfigurationService;
@@ -71,7 +72,7 @@ suite('pytest test discovery adapter', () => {
7172
execService = typeMoq.Mock.ofType<IPythonExecutionService>();
7273
execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
7374
outputChannel = typeMoq.Mock.ofType<ITestOutputChannel>();
74-
75+
interpreterService = typeMoq.Mock.ofType<IInterpreterService>();
7576
const output = new Observable<Output<string>>(() => {
7677
/* no op */
7778
});

0 commit comments

Comments
 (0)