Skip to content

Commit 6333752

Browse files
add envFile's pythonpath before running tests (#22269)
fixes #22231 --------- Co-authored-by: Karthik Nadig <[email protected]>
1 parent 0438813 commit 6333752

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ export class PythonTestServer implements ITestServer, Disposable {
182182
const { uuid } = options;
183183
const isDiscovery = (testIds === undefined || testIds.length === 0) && runTestIdPort === undefined;
184184
const mutableEnv = { ...env };
185-
const pythonPathParts: string[] = process.env.PYTHONPATH?.split(path.delimiter) ?? [];
185+
// get python path from mutable env, it contains process.env as well
186+
const pythonPathParts: string[] = mutableEnv.PYTHONPATH?.split(path.delimiter) ?? [];
186187
const pythonPathCommand = [options.cwd, ...pythonPathParts].join(path.delimiter);
187188
mutableEnv.PYTHONPATH = pythonPathCommand;
188189
mutableEnv.TEST_UUID = uuid.toString();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
7373
const mutableEnv = {
7474
...(await this.envVarsService?.getEnvironmentVariables(uri)),
7575
};
76-
const pythonPathParts: string[] = process.env.PYTHONPATH?.split(path.delimiter) ?? [];
76+
// get python path from mutable env, it contains process.env as well
77+
const pythonPathParts: string[] = mutableEnv.PYTHONPATH?.split(path.delimiter) ?? [];
7778
const pythonPathCommand = [fullPluginPath, ...pythonPathParts].join(path.delimiter);
7879
mutableEnv.PYTHONPATH = pythonPathCommand;
7980
mutableEnv.TEST_UUID = uuid.toString();

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
109109
const { pytestArgs } = settings.testing;
110110
const cwd = settings.testing.cwd && settings.testing.cwd.length > 0 ? settings.testing.cwd : uri.fsPath;
111111
// get and edit env vars
112-
const mutableEnv = { ...(await this.envVarsService?.getEnvironmentVariables(uri)) };
113-
const pythonPathParts: string[] = process.env.PYTHONPATH?.split(path.delimiter) ?? [];
112+
const mutableEnv = {
113+
...(await this.envVarsService?.getEnvironmentVariables(uri)),
114+
};
115+
// get python path from mutable env, it contains process.env as well
116+
const pythonPathParts: string[] = mutableEnv.PYTHONPATH?.split(path.delimiter) ?? [];
114117
const pythonPathCommand = [fullPluginPath, ...pythonPathParts].join(path.delimiter);
115118
mutableEnv.PYTHONPATH = pythonPathCommand;
116119
mutableEnv.TEST_UUID = uuid.toString();

0 commit comments

Comments
 (0)