Skip to content

20711 use cwd in debug testing #21437

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

Merged
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
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