Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug with unittest debug not having args #22169

Merged
merged 3 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading