Skip to content

Commit

Permalink
improve logging for python testing
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Feb 7, 2025
1 parent e8ed713 commit 3259856
Show file tree
Hide file tree
Showing 4 changed files with 28 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

0 comments on commit 3259856

Please sign in to comment.