Skip to content

Commit ff604ca

Browse files
authored
Add cwd to error logs (#22387)
closes #22359
1 parent 78052bd commit ff604ca

File tree

7 files changed

+44
-28
lines changed

7 files changed

+44
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class PythonResultResolver implements ITestResultResolver {
7474
const testingErrorConst =
7575
this.testProvider === 'pytest' ? Testing.errorPytestDiscovery : Testing.errorUnittestDiscovery;
7676
const { error } = rawTestData;
77-
traceError(testingErrorConst, '\r\n', error?.join('\r\n\r\n') ?? '');
77+
traceError(testingErrorConst, 'for workspace: ', workspacePath, '\r\n', error?.join('\r\n\r\n') ?? '');
7878

7979
let errorNode = this.testController.items.get(`DiscoveryError:${workspacePath}`);
8080
const message = util.format(

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,25 +221,25 @@ export class PythonTestServer implements ITestServer, Disposable {
221221
pytestUUID: uuid.toString(),
222222
pytestPort: this.getPort().toString(),
223223
};
224-
traceInfo(`Running DEBUG unittest with arguments: ${args}\r\n`);
224+
traceInfo(`Running DEBUG unittest for workspace ${options.cwd} with arguments: ${args}\r\n`);
225225

226226
await this.debugLauncher!.launchDebugger(launchOptions, () => {
227227
callback?.();
228228
});
229229
} else {
230230
if (isRun) {
231231
// This means it is running the test
232-
traceInfo(`Running unittests with arguments: ${args}\r\n`);
232+
traceInfo(`Running unittests for workspace ${options.cwd} with arguments: ${args}\r\n`);
233233
} else {
234234
// This means it is running discovery
235-
traceLog(`Discovering unittest tests with arguments: ${args}\r\n`);
235+
traceLog(`Discovering unittest tests for workspace ${options.cwd} with arguments: ${args}\r\n`);
236236
}
237237
const deferredTillExecClose = createDeferred<ExecutionResult<string>>();
238238

239239
let resultProc: ChildProcess | undefined;
240240

241241
runInstance?.token.onCancellationRequested(() => {
242-
traceInfo('Test run cancelled, killing unittest subprocess.');
242+
traceInfo(`Test run cancelled, killing unittest subprocess for workspace ${options.cwd}.`);
243243
// if the resultProc exists just call kill on it which will handle resolving the ExecClose deferred, otherwise resolve the deferred here.
244244
if (resultProc) {
245245
resultProc?.kill();
@@ -285,7 +285,7 @@ export class PythonTestServer implements ITestServer, Disposable {
285285
if (code !== 0) {
286286
// This occurs when we are running discovery
287287
traceError(
288-
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal}. Creating and sending error discovery payload`,
288+
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${options.cwd}. Creating and sending error discovery payload \n`,
289289
);
290290
this._onDiscoveryDataReceived.fire({
291291
uuid,
@@ -301,7 +301,7 @@ export class PythonTestServer implements ITestServer, Disposable {
301301
// This occurs when we are running the test and there is an error which occurs.
302302

303303
traceError(
304-
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal}. Creating and sending error execution payload`,
304+
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} for workspace ${options.cwd}. Creating and sending error execution payload \n`,
305305
);
306306
// if the child process exited with a non-zero exit code, then we need to send the error payload.
307307
this._onRunDataReceived.fire({
@@ -319,7 +319,7 @@ export class PythonTestServer implements ITestServer, Disposable {
319319
await deferredTillExecClose.promise;
320320
}
321321
} catch (ex) {
322-
traceError(`Error while server attempting to run unittest command: ${ex}`);
322+
traceError(`Error while server attempting to run unittest command for workspace ${options.cwd}: ${ex}`);
323323
this.uuids = this.uuids.filter((u) => u !== uuid);
324324
this._onDataReceived.fire({
325325
uuid,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export function createExecutionErrorPayload(
297297
const etp: ExecutionTestPayload = {
298298
cwd,
299299
status: 'error',
300-
error: 'Test run failed, the python test process was terminated before it could exit on its own.',
300+
error: `Test run failed, the python test process was terminated before it could exit on its own for workspace ${cwd}`,
301301
result: {},
302302
};
303303
// add error result for each attempted test.
@@ -321,7 +321,7 @@ export function createDiscoveryErrorPayload(
321321
cwd,
322322
status: 'error',
323323
error: [
324-
` \n The python test process was terminated before it could exit on its own, the process errored with: Code: ${code}, Signal: ${signal}`,
324+
` \n The python test process was terminated before it could exit on its own, the process errored with: Code: ${code}, Signal: ${signal} for workspace ${cwd}`,
325325
],
326326
};
327327
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
5454
await this.runPytestDiscovery(uri, uuid, executionFactory);
5555
} finally {
5656
await deferredTillEOT.promise;
57-
traceVerbose('deferredTill EOT resolved');
57+
traceVerbose(`deferredTill EOT resolved for ${uri.fsPath}`);
5858
disposeDataReceiver(this.testServer);
5959
}
6060
// this is only a placeholder to handle function overloading until rewrite is finished
@@ -79,7 +79,11 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
7979
mutableEnv.PYTHONPATH = pythonPathCommand;
8080
mutableEnv.TEST_UUID = uuid.toString();
8181
mutableEnv.TEST_PORT = this.testServer.getPort().toString();
82-
traceInfo(`All environment variables set for pytest discovery: ${JSON.stringify(mutableEnv)}`);
82+
traceInfo(
83+
`All environment variables set for pytest discovery for workspace ${uri.fsPath}: ${JSON.stringify(
84+
mutableEnv,
85+
)} \n`,
86+
);
8387
const spawnOptions: SpawnOptions = {
8488
cwd,
8589
throwOnStdErr: true,
@@ -95,7 +99,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
9599
const execService = await executionFactory?.createActivatedEnvironment(creationOptions);
96100
// delete UUID following entire discovery finishing.
97101
const execArgs = ['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only'].concat(pytestArgs);
98-
traceVerbose(`Running pytest discovery with command: ${execArgs.join(' ')}`);
102+
traceVerbose(`Running pytest discovery with command: ${execArgs.join(' ')} for workspace ${uri.fsPath}.`);
99103

100104
const deferredTillExecClose: Deferred<void> = createTestingDeferred();
101105
const result = execService?.execObservable(execArgs, spawnOptions);
@@ -117,7 +121,9 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
117121
result?.proc?.on('exit', (code, signal) => {
118122
this.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE);
119123
if (code !== 0) {
120-
traceError(`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal}.`);
124+
traceError(
125+
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}.`,
126+
);
121127
}
122128
});
123129
result?.proc?.on('close', (code, signal) => {

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
5353
const eParsed = JSON.parse(e.data);
5454
this.resultResolver?.resolveExecution(eParsed, runInstance, deferredTillEOT);
5555
} else {
56-
traceError('No run instance found, cannot resolve execution.');
56+
traceError(`No run instance found, cannot resolve execution, for workspace ${uri.fsPath}.`);
5757
}
5858
});
5959
const disposeDataReceiver = function (testServer: ITestServer) {
@@ -62,7 +62,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
6262
dataReceivedDisposable.dispose();
6363
};
6464
runInstance?.token.onCancellationRequested(() => {
65-
traceInfo("Test run cancelled, resolving 'till EOT' deferred.");
65+
traceInfo(`Test run cancelled, resolving 'till EOT' deferred for ${uri.fsPath}.`);
6666
deferredTillEOT.resolve();
6767
});
6868

@@ -143,7 +143,11 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
143143
// add port with run test ids to env vars
144144
const pytestRunTestIdsPort = await utils.startTestIdServer(testIds);
145145
mutableEnv.RUN_TEST_IDS_PORT = pytestRunTestIdsPort.toString();
146-
traceInfo(`All environment variables set for pytest execution: ${JSON.stringify(mutableEnv)}`);
146+
traceInfo(
147+
`All environment variables set for pytest execution in ${uri.fsPath} workspace: \n ${JSON.stringify(
148+
mutableEnv,
149+
)}`,
150+
);
147151

148152
const spawnOptions: SpawnOptions = {
149153
cwd,
@@ -165,7 +169,9 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
165169
pytestUUID,
166170
runTestIdsPort: pytestRunTestIdsPort.toString(),
167171
};
168-
traceInfo(`Running DEBUG pytest with arguments: ${testArgs.join(' ')}\r\n`);
172+
traceInfo(
173+
`Running DEBUG pytest with arguments: ${testArgs.join(' ')} for workspace ${uri.fsPath} \r\n`,
174+
);
169175
await debugLauncher!.launchDebugger(launchOptions, () => {
170176
deferredTillEOT?.resolve();
171177
});
@@ -175,12 +181,12 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
175181
// combine path to run script with run args
176182
const scriptPath = path.join(fullPluginPath, 'vscode_pytest', 'run_pytest_script.py');
177183
const runArgs = [scriptPath, ...testArgs];
178-
traceInfo(`Running pytest with arguments: ${runArgs.join(' ')}\r\n`);
184+
traceInfo(`Running pytest with arguments: ${runArgs.join(' ')} for workspace ${uri.fsPath} \r\n`);
179185

180186
let resultProc: ChildProcess | undefined;
181187

182188
runInstance?.token.onCancellationRequested(() => {
183-
traceInfo('Test run cancelled, killing pytest subprocess.');
189+
traceInfo(`Test run cancelled, killing pytest subprocess for workspace ${uri.fsPath}`);
184190
// if the resultProc exists just call kill on it which will handle resolving the ExecClose deferred, otherwise resolve the deferred here.
185191
if (resultProc) {
186192
resultProc?.kill();
@@ -208,7 +214,9 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
208214
result?.proc?.on('exit', (code, signal) => {
209215
this.outputChannel?.append(utils.MESSAGE_ON_TESTING_OUTPUT_MOVE);
210216
if (code !== 0 && testIds) {
211-
traceError(`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal}.`);
217+
traceError(
218+
`Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`,
219+
);
212220
}
213221
});
214222

@@ -218,7 +226,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
218226
// if the child process exited with a non-zero exit code, then we need to send the error payload.
219227
if (code !== 0 && testIds) {
220228
traceError(
221-
`Subprocess closed unsuccessfully with exit code ${code} and signal ${signal}. Creating and sending error execution payload`,
229+
`Subprocess closed unsuccessfully with exit code ${code} and signal ${signal} for workspace ${uri.fsPath}. Creating and sending error execution payload \n`,
222230
);
223231
this.testServer.triggerRunDataReceivedEvent({
224232
uuid,
@@ -237,7 +245,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
237245
await deferredTillExecClose?.promise;
238246
}
239247
} catch (ex) {
240-
traceError(`Error while running tests: ${testIds}\r\n${ex}\r\n\r\n`);
248+
traceError(`Error while running tests for workspace ${uri}: ${testIds}\r\n${ex}\r\n\r\n`);
241249
return Promise.reject(ex);
242250
}
243251

src/client/testing/testController/workspaceTestAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class WorkspaceTestAdapter {
143143
cancel = token?.isCancellationRequested ? Testing.cancelPytestDiscovery : Testing.errorPytestDiscovery;
144144
}
145145

146-
traceError(`${cancel}\r\n`, ex);
146+
traceError(`${cancel} for workspace: ${this.workspaceUri} \r\n`, ex);
147147

148148
// Report also on the test view.
149149
const message = util.format(`${cancel} ${Testing.seePythonOutput}\r\n`, ex);

src/test/testing/testController/workspaceTestAdapter.unit.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ITestResultResolver, ITestServer } from '../../../client/testing/testCo
1616
import * as testItemUtilities from '../../../client/testing/testController/common/testItemUtilities';
1717
import * as util from '../../../client/testing/testController/common/utils';
1818
import * as ResultResolver from '../../../client/testing/testController/common/resultResolver';
19+
import { IPythonExecutionFactory } from '../../../client/common/process/types';
1920

2021
suite('Workspace test adapter', () => {
2122
suite('Test discovery', () => {
@@ -137,12 +138,12 @@ suite('Workspace test adapter', () => {
137138
stubConfigSettings,
138139
outputChannel.object,
139140
);
140-
141+
const uriFoo = Uri.parse('foo');
141142
const workspaceTestAdapter = new WorkspaceTestAdapter(
142143
'unittest',
143144
testDiscoveryAdapter,
144145
testExecutionAdapter,
145-
Uri.parse('foo'),
146+
uriFoo,
146147
stubResultResolver,
147148
);
148149

@@ -164,10 +165,11 @@ suite('Workspace test adapter', () => {
164165
const buildErrorNodeOptionsStub = sinon.stub(util, 'buildErrorNodeOptions').returns(errorTestItemOptions);
165166
const testProvider = 'unittest';
166167

167-
await workspaceTestAdapter.discoverTests(testController);
168+
const execFactory = typemoq.Mock.ofType<IPythonExecutionFactory>();
169+
await workspaceTestAdapter.discoverTests(testController, undefined, execFactory.object);
168170

169171
sinon.assert.calledWithMatch(createErrorTestItemStub, sinon.match.any, sinon.match.any);
170-
sinon.assert.calledWithMatch(buildErrorNodeOptionsStub, Uri.parse('foo'), sinon.match.any, testProvider);
172+
sinon.assert.calledWithMatch(buildErrorNodeOptionsStub, uriFoo, sinon.match.any, testProvider);
171173
});
172174

173175
test("When discovering tests, the workspace test adapter should call the test discovery adapter's discoverTest method", async () => {

0 commit comments

Comments
 (0)