Skip to content

Commit 091e121

Browse files
authored
fix bug with unittest debug not having args (#22169)
1 parent e7dfef8 commit 091e121

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

src/client/testing/common/debugLauncher.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,13 @@ export class DebugLauncher implements ITestDebugLauncher {
205205
}
206206
launchArgs.request = 'launch';
207207

208-
// Both types of tests need to have the port for the test result server.
209-
if (options.runTestIdsPort) {
210-
launchArgs.env = {
211-
...launchArgs.env,
212-
RUN_TEST_IDS_PORT: options.runTestIdsPort,
213-
};
214-
}
215-
if (options.testProvider === 'pytest' && pythonTestAdapterRewriteExperiment) {
216-
if (options.pytestPort && options.pytestUUID) {
208+
if (pythonTestAdapterRewriteExperiment) {
209+
if (options.pytestPort && options.pytestUUID && options.runTestIdsPort) {
217210
launchArgs.env = {
218211
...launchArgs.env,
219212
TEST_PORT: options.pytestPort,
220213
TEST_UUID: options.pytestUUID,
214+
RUN_TEST_IDS_PORT: options.runTestIdsPort,
221215
};
222216
} else {
223217
throw Error(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ export class PythonTestServer implements ITestServer, Disposable {
211211
token: options.token,
212212
testProvider: UNITTEST_PROVIDER,
213213
runTestIdsPort: runTestIdPort,
214+
pytestUUID: uuid.toString(),
215+
pytestPort: this.getPort().toString(),
214216
};
215217
traceInfo(`Running DEBUG unittest with arguments: ${args}\r\n`);
216218

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Output,
1717
} from '../../../client/common/process/types';
1818
import { PythonTestServer } from '../../../client/testing/testController/common/server';
19-
import { ITestDebugLauncher } from '../../../client/testing/common/types';
19+
import { ITestDebugLauncher, LaunchOptions } from '../../../client/testing/common/types';
2020
import { Deferred, createDeferred } from '../../../client/common/utils/async';
2121
import { MockChildProcess } from '../../mocks/mockChildProcess';
2222
import {
@@ -240,6 +240,64 @@ suite('Python Test Server, Send command etc', () => {
240240
assert(false, errorMessage);
241241
}
242242
});
243+
test('sendCommand should add right extra variables to command during debug', async () => {
244+
const deferred2 = createDeferred();
245+
const RUN_TEST_IDS_PORT_CONST = '5678';
246+
const error = false;
247+
const errorMessage = '';
248+
const debugLauncherMock = typeMoq.Mock.ofType<ITestDebugLauncher>();
249+
let actualLaunchOptions: LaunchOptions = {} as LaunchOptions;
250+
const deferred4 = createDeferred();
251+
debugLauncherMock
252+
.setup((x) => x.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny()))
253+
.returns((options, _) => {
254+
actualLaunchOptions = options;
255+
deferred4.resolve();
256+
return Promise.resolve();
257+
});
258+
execService
259+
.setup((x) => x.execObservable(typeMoq.It.isAny(), typeMoq.It.isAny()))
260+
.returns(() => typeMoq.Mock.ofType<ObservableExecutionResult<string>>().object);
261+
const execFactory = typeMoq.Mock.ofType<IPythonExecutionFactory>();
262+
execFactory
263+
.setup((x) => x.createActivatedEnvironment(typeMoq.It.isAny()))
264+
.returns(() => {
265+
deferred2.resolve();
266+
return Promise.resolve(execService.object);
267+
});
268+
server = new PythonTestServer(execFactory.object, debugLauncherMock.object);
269+
sinon.stub(server, 'getPort').returns(12345);
270+
// const portServer = server.getPort();
271+
await server.serverReady();
272+
const options = {
273+
command: { script: 'myscript', args: ['-foo', 'foo'] },
274+
workspaceFolder: Uri.file('/foo/bar'),
275+
cwd: '/foo/bar',
276+
uuid: FAKE_UUID,
277+
debugBool: true,
278+
};
279+
try {
280+
server.sendCommand(options, {}, RUN_TEST_IDS_PORT_CONST);
281+
} catch (e) {
282+
assert(false, `Error sending command, ${e}`);
283+
}
284+
// add in await and trigger
285+
await deferred2.promise;
286+
await deferred4.promise;
287+
mockProc.trigger('close');
288+
289+
assert.notDeepEqual(actualLaunchOptions, {}, 'launch options should be set');
290+
assert.strictEqual(actualLaunchOptions.cwd, '/foo/bar');
291+
assert.strictEqual(actualLaunchOptions.testProvider, 'unittest');
292+
assert.strictEqual(actualLaunchOptions.pytestPort, '12345');
293+
assert.strictEqual(actualLaunchOptions.pytestUUID, 'fake-uuid');
294+
assert.strictEqual(actualLaunchOptions.runTestIdsPort, '5678');
295+
296+
debugLauncherMock.verify((x) => x.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny()), typeMoq.Times.once());
297+
if (error) {
298+
assert(false, errorMessage);
299+
}
300+
});
243301

244302
test('sendCommand should write to an output channel if it is provided as an option', async () => {
245303
const output2: string[] = [];

0 commit comments

Comments
 (0)