Skip to content

Commit

Permalink
20711 use cwd in debug testing (#21437)
Browse files Browse the repository at this point in the history
Closed: #20711
  • Loading branch information
paulacamargo25 authored Jun 15, 2023
1 parent 88e2ef5 commit 3dc11d2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/client/testing/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class DebugLauncher implements ITestDebugLauncher {
cfg.console = 'internalConsole';
}
if (!cfg.cwd) {
cfg.cwd = workspaceFolder.uri.fsPath;
cfg.cwd = configSettings.testing.cwd || workspaceFolder.uri.fsPath;
}
if (!cfg.env) {
cfg.env = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {

public async runTests(uri: Uri, testIds: string[], debugBool?: boolean): Promise<ExecutionTestPayload> {
const settings = this.configSettings.getSettings(uri);
const { unittestArgs } = settings.testing;
const { cwd, unittestArgs } = settings.testing;

const command = buildExecutionCommand(unittestArgs);
this.cwd = uri.fsPath;
this.cwd = cwd || uri.fsPath;
const uuid = this.testServer.createUUID(uri.fsPath);

const options: TestCommandOptions = {
Expand Down
17 changes: 16 additions & 1 deletion src/test/testing/common/debugLauncher.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ suite('Unit Tests - Debug Launcher', () => {
settings = TypeMoq.Mock.ofType<IPythonSettings>(undefined, TypeMoq.MockBehavior.Strict);
configService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object);

unitTestSettings = TypeMoq.Mock.ofType<ITestingSettings>(undefined, TypeMoq.MockBehavior.Strict);
unitTestSettings = TypeMoq.Mock.ofType<ITestingSettings>();
settings.setup((p) => p.testing).returns(() => unitTestSettings.object);

debugEnvHelper = TypeMoq.Mock.ofType<IDebugEnvironmentVariablesService>(undefined, TypeMoq.MockBehavior.Strict);
Expand Down Expand Up @@ -333,6 +333,21 @@ suite('Unit Tests - Debug Launcher', () => {
debugService.verifyAll();
});

test('Use cwd value in settings if exist', async () => {
unitTestSettings.setup((p) => p.cwd).returns(() => 'path/to/settings/cwd');
const options: LaunchOptions = {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
};
const expected = getDefaultDebugConfig();
expected.cwd = 'path/to/settings/cwd';
setupSuccess(options, 'unittest', expected);
await debugLauncher.launchDebugger(options);

debugService.verifyAll();
});

test('Full debug config', async () => {
const options: LaunchOptions = {
cwd: 'one/two/three',
Expand Down

0 comments on commit 3dc11d2

Please sign in to comment.