Skip to content

Commit

Permalink
fix bug with unittest debug not having args (microsoft#22169)
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd authored Oct 7, 2023
1 parent e7dfef8 commit 091e121
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/client/testing/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,13 @@ export class DebugLauncher implements ITestDebugLauncher {
}
launchArgs.request = 'launch';

// Both types of tests need to have the port for the test result server.
if (options.runTestIdsPort) {
launchArgs.env = {
...launchArgs.env,
RUN_TEST_IDS_PORT: options.runTestIdsPort,
};
}
if (options.testProvider === 'pytest' && pythonTestAdapterRewriteExperiment) {
if (options.pytestPort && options.pytestUUID) {
if (pythonTestAdapterRewriteExperiment) {
if (options.pytestPort && options.pytestUUID && options.runTestIdsPort) {
launchArgs.env = {
...launchArgs.env,
TEST_PORT: options.pytestPort,
TEST_UUID: options.pytestUUID,
RUN_TEST_IDS_PORT: options.runTestIdsPort,
};
} else {
throw Error(
Expand Down
2 changes: 2 additions & 0 deletions src/client/testing/testController/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ export class PythonTestServer implements ITestServer, Disposable {
token: options.token,
testProvider: UNITTEST_PROVIDER,
runTestIdsPort: runTestIdPort,
pytestUUID: uuid.toString(),
pytestPort: this.getPort().toString(),
};
traceInfo(`Running DEBUG unittest with arguments: ${args}\r\n`);

Expand Down
60 changes: 59 additions & 1 deletion src/test/testing/testController/server.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Output,
} from '../../../client/common/process/types';
import { PythonTestServer } from '../../../client/testing/testController/common/server';
import { ITestDebugLauncher } from '../../../client/testing/common/types';
import { ITestDebugLauncher, LaunchOptions } from '../../../client/testing/common/types';
import { Deferred, createDeferred } from '../../../client/common/utils/async';
import { MockChildProcess } from '../../mocks/mockChildProcess';
import {
Expand Down Expand Up @@ -240,6 +240,64 @@ suite('Python Test Server, Send command etc', () => {
assert(false, errorMessage);
}
});
test('sendCommand should add right extra variables to command during debug', async () => {
const deferred2 = createDeferred();
const RUN_TEST_IDS_PORT_CONST = '5678';
const error = false;
const errorMessage = '';
const debugLauncherMock = typeMoq.Mock.ofType<ITestDebugLauncher>();
let actualLaunchOptions: LaunchOptions = {} as LaunchOptions;
const deferred4 = createDeferred();
debugLauncherMock
.setup((x) => x.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny()))
.returns((options, _) => {
actualLaunchOptions = options;
deferred4.resolve();
return Promise.resolve();
});
execService
.setup((x) => x.execObservable(typeMoq.It.isAny(), typeMoq.It.isAny()))
.returns(() => typeMoq.Mock.ofType<ObservableExecutionResult<string>>().object);
const execFactory = typeMoq.Mock.ofType<IPythonExecutionFactory>();
execFactory
.setup((x) => x.createActivatedEnvironment(typeMoq.It.isAny()))
.returns(() => {
deferred2.resolve();
return Promise.resolve(execService.object);
});
server = new PythonTestServer(execFactory.object, debugLauncherMock.object);
sinon.stub(server, 'getPort').returns(12345);
// const portServer = server.getPort();
await server.serverReady();
const options = {
command: { script: 'myscript', args: ['-foo', 'foo'] },
workspaceFolder: Uri.file('/foo/bar'),
cwd: '/foo/bar',
uuid: FAKE_UUID,
debugBool: true,
};
try {
server.sendCommand(options, {}, RUN_TEST_IDS_PORT_CONST);
} catch (e) {
assert(false, `Error sending command, ${e}`);
}
// add in await and trigger
await deferred2.promise;
await deferred4.promise;
mockProc.trigger('close');

assert.notDeepEqual(actualLaunchOptions, {}, 'launch options should be set');
assert.strictEqual(actualLaunchOptions.cwd, '/foo/bar');
assert.strictEqual(actualLaunchOptions.testProvider, 'unittest');
assert.strictEqual(actualLaunchOptions.pytestPort, '12345');
assert.strictEqual(actualLaunchOptions.pytestUUID, 'fake-uuid');
assert.strictEqual(actualLaunchOptions.runTestIdsPort, '5678');

debugLauncherMock.verify((x) => x.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny()), typeMoq.Times.once());
if (error) {
assert(false, errorMessage);
}
});

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

0 comments on commit 091e121

Please sign in to comment.