Skip to content

Commit

Permalink
add logging + move service container
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Oct 30, 2024
1 parent 36cac6f commit 7763016
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/client/testing/testController/pytest/pytestExecutionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
const settings = this.configSettings.getSettings(uri);
const { pytestArgs } = settings.testing;
const cwd = settings.testing.cwd && settings.testing.cwd.length > 0 ? settings.testing.cwd : uri.fsPath;
console.log('EJFB, runTestNew');
// get and edit env vars
const mutableEnv = {
...(await this.envVarsService?.getEnvironmentVariables(uri)),
};
console.log('EJFB after mutableEnv');
// get python path from mutable env, it contains process.env as well
const pythonPathParts: string[] = mutableEnv.PYTHONPATH?.split(path.delimiter) ?? [];
const pythonPathCommand = [fullPluginPath, ...pythonPathParts].join(path.delimiter);
Expand All @@ -121,15 +123,17 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
mutableEnv.COVERAGE_ENABLED = 'True';
}
const debugBool = profileKind && profileKind === TestRunProfileKind.Debug;

console.log('EJFB after debug Bool');
// Create the Python environment in which to execute the command.
const creationOptions: ExecutionFactoryCreateWithEnvironmentOptions = {
allowEnvironmentFetchExceptions: false,
resource: uri,
interpreter,
};
// need to check what will happen in the exec service is NOT defined and is null
console.log('EJFB, before exec service');
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
console.log('EJFB, after exec service');
try {
// Remove positional test folders and files, we will add as needed per node
let testArgs = removePositionalFoldersAndFiles(pytestArgs);
Expand Down Expand Up @@ -157,7 +161,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
env: mutableEnv,
token: runInstance?.token,
};

console.log('EJFB, before debug check');
if (debugBool) {
const launchOptions: LaunchOptions = {
cwd,
Expand All @@ -181,6 +185,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {

let resultProc: ChildProcess | undefined;

console.log('EJFB, before run instance creation');
runInstance?.token.onCancellationRequested(() => {
traceInfo(`Test run cancelled, killing pytest subprocess for workspace ${uri.fsPath}`);
// if the resultProc exists just call kill on it which will handle resolving the ExecClose deferred, otherwise resolve the deferred here.
Expand All @@ -192,7 +197,9 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
}
});

console.log('EJFB, before exec observable');
const result = execService?.execObservable(runArgs, spawnOptions);
console.log('EJFB, after exec observable');
resultProc = result?.proc;

// Take all output from the subprocess and add it to the test output channel. This will be the pytest output.
Expand All @@ -219,6 +226,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {

result?.proc?.on('close', (code, signal) => {
traceVerbose('Test run finished, subprocess closed.');
console.log('EJFB, process closed');
// if the child has testIds then this is a run request
// if the child process exited with a non-zero exit code, then we need to send the error payload.
if (code !== 0 && testIds) {
Expand All @@ -239,6 +247,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
deferredTillExecClose.resolve();
serverCancel.cancel();
});
console.log('EJFB, await deferredTillExecClose');
await deferredTillExecClose.promise;
}
} catch (ex) {
Expand All @@ -251,6 +260,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
status: 'success',
error: '',
};
console.log('EJFB, returning execution payload');
return executionPayload;
}
}
3 changes: 1 addition & 2 deletions src/test/testing/common/testingAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ suite('End to End Tests: test adapters', () => {
// create symlink for specific symlink test
const target = rootPathSmallWorkspace;
const dest = rootPathDiscoverySymlink;
serviceContainer = (await initialize()).serviceContainer;
try {
fs.symlink(target, dest, 'dir', (err) => {
if (err) {
Expand All @@ -105,7 +106,6 @@ suite('End to End Tests: test adapters', () => {
});

setup(async () => {
serviceContainer = (await initialize()).serviceContainer;
getPixiStub = sinon.stub(pixi, 'getPixi');
getPixiStub.resolves(undefined);

Expand Down Expand Up @@ -1143,7 +1143,6 @@ suite('End to End Tests: test adapters', () => {
let callCount = 0;
let failureOccurred = false;
let failureMsg = '';
console.log('EFB: beginning function');
resultResolver._resolveExecution = async (data, _token?) => {
// do the following asserts for each time resolveExecution is called, should be called once per test.
console.log(`pytest execution adapter seg fault error handling \n ${JSON.stringify(data)}`);
Expand Down

0 comments on commit 7763016

Please sign in to comment.