Skip to content

Commit 0983657

Browse files
authored
improve logging for python testing (#24799)
will help provide clarity for #24585
1 parent 32c2cf9 commit 0983657

8 files changed

+34
-5
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
111111
const pythonPathCommand = [fullPluginPath, ...pythonPathParts].join(path.delimiter);
112112
mutableEnv.PYTHONPATH = pythonPathCommand;
113113
mutableEnv.TEST_RUN_PIPE = discoveryPipeName;
114-
traceInfo(`All environment variables set for pytest discovery: ${JSON.stringify(mutableEnv)}`);
114+
traceInfo(
115+
`All environment variables set for pytest discovery, PYTHONPATH: ${JSON.stringify(mutableEnv.PYTHONPATH)}`,
116+
);
115117

116118
// delete UUID following entire discovery finishing.
117119
const execArgs = ['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs);
@@ -176,6 +178,9 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
176178
};
177179
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
178180

181+
const execInfo = await execService?.getExecutablePath();
182+
traceVerbose(`Executable path for pytest discovery: ${execInfo}.`);
183+
179184
const deferredTillExecClose: Deferred<void> = createTestingDeferred();
180185

181186
let resultProc: ChildProcess | undefined;

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
116116
};
117117
// need to check what will happen in the exec service is NOT defined and is null
118118
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
119+
120+
const execInfo = await execService?.getExecutablePath();
121+
traceVerbose(`Executable path for pytest execution: ${execInfo}.`);
122+
119123
try {
120124
// Remove positional test folders and files, we will add as needed per node
121125
let testArgs = removePositionalFoldersAndFiles(pytestArgs);
@@ -133,7 +137,11 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
133137
// create a file with the test ids and set the environment variable to the file name
134138
const testIdsFileName = await utils.writeTestIdsFile(testIds);
135139
mutableEnv.RUN_TEST_IDS_PIPE = testIdsFileName;
136-
traceInfo(`All environment variables set for pytest execution: ${JSON.stringify(mutableEnv)}`);
140+
traceInfo(
141+
`All environment variables set for pytest execution, PYTHONPATH: ${JSON.stringify(
142+
mutableEnv.PYTHONPATH,
143+
)}`,
144+
);
137145

138146
const spawnOptions: SpawnOptions = {
139147
cwd,

src/client/testing/testController/unittest/testDiscoveryAdapter.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
fixLogLinesNoTrailing,
2929
startDiscoveryNamedPipe,
3030
} from '../common/utils';
31-
import { traceError, traceInfo, traceLog } from '../../../logging';
31+
import { traceError, traceInfo, traceLog, traceVerbose } from '../../../logging';
3232
import { getEnvironment, runInBackground, useEnvExtension } from '../../../envExt/api.internal';
3333

3434
/**
@@ -169,6 +169,8 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
169169
resource: options.workspaceFolder,
170170
};
171171
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
172+
const execInfo = await execService?.getExecutablePath();
173+
traceVerbose(`Executable path for unittest discovery: ${execInfo}.`);
172174

173175
let resultProc: ChildProcess | undefined;
174176
options.token?.onCancellationRequested(() => {

src/client/testing/testController/unittest/testExecutionAdapter.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
TestCommandOptions,
1515
TestExecutionCommand,
1616
} from '../common/types';
17-
import { traceError, traceInfo, traceLog } from '../../../logging';
17+
import { traceError, traceInfo, traceLog, traceVerbose } from '../../../logging';
1818
import { MESSAGE_ON_TESTING_OUTPUT_MOVE, fixLogLinesNoTrailing } from '../common/utils';
1919
import { EnvironmentVariables, IEnvironmentVariablesProvider } from '../../../common/variables/types';
2020
import {
@@ -130,7 +130,11 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
130130
// create named pipe server to send test ids
131131
const testIdsFileName = await utils.writeTestIdsFile(testIds);
132132
mutableEnv.RUN_TEST_IDS_PIPE = testIdsFileName;
133-
traceInfo(`All environment variables set for pytest execution: ${JSON.stringify(mutableEnv)}`);
133+
traceInfo(
134+
`All environment variables set for unittest execution, PYTHONPATH: ${JSON.stringify(
135+
mutableEnv.PYTHONPATH,
136+
)}`,
137+
);
134138

135139
const spawnOptions: SpawnOptions = {
136140
token: options.token,
@@ -145,6 +149,10 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
145149
resource: options.workspaceFolder,
146150
};
147151
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
152+
153+
const execInfo = await execService?.getExecutablePath();
154+
traceVerbose(`Executable path for unittest execution: ${execInfo}.`);
155+
148156
const args = [options.command.script].concat(options.command.args);
149157

150158
if (options.outChannel) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ suite('pytest test discovery adapter', () => {
7171
mockProc = new MockChildProcess('', ['']);
7272
execService = typeMoq.Mock.ofType<IPythonExecutionService>();
7373
execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
74+
execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python'));
7475
outputChannel = typeMoq.Mock.ofType<ITestOutputChannel>();
7576

7677
const output = new Observable<Output<string>>(() => {

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

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ suite('pytest test execution adapter', () => {
8989

9090
utilsStartRunResultNamedPipeStub = sinon.stub(util, 'startRunResultNamedPipe');
9191
utilsStartRunResultNamedPipeStub.callsFake(() => Promise.resolve('runResultPipe-mockName'));
92+
93+
execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python'));
9294
});
9395
teardown(() => {
9496
sinon.restore();

src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ suite('Unittest test discovery adapter', () => {
6868
},
6969
};
7070
});
71+
execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python'));
7172
execFactory = typeMoq.Mock.ofType<IPythonExecutionFactory>();
7273
deferred = createDeferred();
7374
execFactory

src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ suite('Unittest test execution adapter', () => {
8888

8989
utilsStartRunResultNamedPipeStub = sinon.stub(util, 'startRunResultNamedPipe');
9090
utilsStartRunResultNamedPipeStub.callsFake(() => Promise.resolve('runResultPipe-mockName'));
91+
92+
execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python'));
9193
});
9294
teardown(() => {
9395
sinon.restore();

0 commit comments

Comments
 (0)