Skip to content

Commit

Permalink
improve logging for python testing (#24799)
Browse files Browse the repository at this point in the history
will help provide clarity for
#24585
  • Loading branch information
eleanorjboyd authored Feb 7, 2025
1 parent 32c2cf9 commit 0983657
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
const pythonPathCommand = [fullPluginPath, ...pythonPathParts].join(path.delimiter);
mutableEnv.PYTHONPATH = pythonPathCommand;
mutableEnv.TEST_RUN_PIPE = discoveryPipeName;
traceInfo(`All environment variables set for pytest discovery: ${JSON.stringify(mutableEnv)}`);
traceInfo(
`All environment variables set for pytest discovery, PYTHONPATH: ${JSON.stringify(mutableEnv.PYTHONPATH)}`,
);

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

const execInfo = await execService?.getExecutablePath();
traceVerbose(`Executable path for pytest discovery: ${execInfo}.`);

const deferredTillExecClose: Deferred<void> = createTestingDeferred();

let resultProc: ChildProcess | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
};
// need to check what will happen in the exec service is NOT defined and is null
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);

const execInfo = await execService?.getExecutablePath();
traceVerbose(`Executable path for pytest execution: ${execInfo}.`);

try {
// Remove positional test folders and files, we will add as needed per node
let testArgs = removePositionalFoldersAndFiles(pytestArgs);
Expand All @@ -133,7 +137,11 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
// create a file with the test ids and set the environment variable to the file name
const testIdsFileName = await utils.writeTestIdsFile(testIds);
mutableEnv.RUN_TEST_IDS_PIPE = testIdsFileName;
traceInfo(`All environment variables set for pytest execution: ${JSON.stringify(mutableEnv)}`);
traceInfo(
`All environment variables set for pytest execution, PYTHONPATH: ${JSON.stringify(
mutableEnv.PYTHONPATH,
)}`,
);

const spawnOptions: SpawnOptions = {
cwd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
fixLogLinesNoTrailing,
startDiscoveryNamedPipe,
} from '../common/utils';
import { traceError, traceInfo, traceLog } from '../../../logging';
import { traceError, traceInfo, traceLog, traceVerbose } from '../../../logging';
import { getEnvironment, runInBackground, useEnvExtension } from '../../../envExt/api.internal';

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

let resultProc: ChildProcess | undefined;
options.token?.onCancellationRequested(() => {
Expand Down
12 changes: 10 additions & 2 deletions src/client/testing/testController/unittest/testExecutionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
TestCommandOptions,
TestExecutionCommand,
} from '../common/types';
import { traceError, traceInfo, traceLog } from '../../../logging';
import { traceError, traceInfo, traceLog, traceVerbose } from '../../../logging';
import { MESSAGE_ON_TESTING_OUTPUT_MOVE, fixLogLinesNoTrailing } from '../common/utils';
import { EnvironmentVariables, IEnvironmentVariablesProvider } from '../../../common/variables/types';
import {
Expand Down Expand Up @@ -130,7 +130,11 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
// create named pipe server to send test ids
const testIdsFileName = await utils.writeTestIdsFile(testIds);
mutableEnv.RUN_TEST_IDS_PIPE = testIdsFileName;
traceInfo(`All environment variables set for pytest execution: ${JSON.stringify(mutableEnv)}`);
traceInfo(
`All environment variables set for unittest execution, PYTHONPATH: ${JSON.stringify(
mutableEnv.PYTHONPATH,
)}`,
);

const spawnOptions: SpawnOptions = {
token: options.token,
Expand All @@ -145,6 +149,10 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
resource: options.workspaceFolder,
};
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);

const execInfo = await execService?.getExecutablePath();
traceVerbose(`Executable path for unittest execution: ${execInfo}.`);

const args = [options.command.script].concat(options.command.args);

if (options.outChannel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ suite('pytest test discovery adapter', () => {
mockProc = new MockChildProcess('', ['']);
execService = typeMoq.Mock.ofType<IPythonExecutionService>();
execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python'));
outputChannel = typeMoq.Mock.ofType<ITestOutputChannel>();

const output = new Observable<Output<string>>(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ suite('pytest test execution adapter', () => {

utilsStartRunResultNamedPipeStub = sinon.stub(util, 'startRunResultNamedPipe');
utilsStartRunResultNamedPipeStub.callsFake(() => Promise.resolve('runResultPipe-mockName'));

execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python'));
});
teardown(() => {
sinon.restore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ suite('Unittest test discovery adapter', () => {
},
};
});
execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python'));
execFactory = typeMoq.Mock.ofType<IPythonExecutionFactory>();
deferred = createDeferred();
execFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ suite('Unittest test execution adapter', () => {

utilsStartRunResultNamedPipeStub = sinon.stub(util, 'startRunResultNamedPipe');
utilsStartRunResultNamedPipeStub.callsFake(() => Promise.resolve('runResultPipe-mockName'));

execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python'));
});
teardown(() => {
sinon.restore();
Expand Down

0 comments on commit 0983657

Please sign in to comment.