Skip to content

Commit 3dc11d2

Browse files
20711 use cwd in debug testing (#21437)
Closed: #20711
1 parent 88e2ef5 commit 3dc11d2

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/client/testing/common/debugLauncher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class DebugLauncher implements ITestDebugLauncher {
146146
cfg.console = 'internalConsole';
147147
}
148148
if (!cfg.cwd) {
149-
cfg.cwd = workspaceFolder.uri.fsPath;
149+
cfg.cwd = configSettings.testing.cwd || workspaceFolder.uri.fsPath;
150150
}
151151
if (!cfg.env) {
152152
cfg.env = {};

src/client/testing/testController/unittest/testExecutionAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
4444

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

4949
const command = buildExecutionCommand(unittestArgs);
50-
this.cwd = uri.fsPath;
50+
this.cwd = cwd || uri.fsPath;
5151
const uuid = this.testServer.createUUID(uri.fsPath);
5252

5353
const options: TestCommandOptions = {

src/test/testing/common/debugLauncher.unit.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ suite('Unit Tests - Debug Launcher', () => {
7777
settings = TypeMoq.Mock.ofType<IPythonSettings>(undefined, TypeMoq.MockBehavior.Strict);
7878
configService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object);
7979

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

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

336+
test('Use cwd value in settings if exist', async () => {
337+
unitTestSettings.setup((p) => p.cwd).returns(() => 'path/to/settings/cwd');
338+
const options: LaunchOptions = {
339+
cwd: 'one/two/three',
340+
args: ['/one/two/three/testfile.py'],
341+
testProvider: 'unittest',
342+
};
343+
const expected = getDefaultDebugConfig();
344+
expected.cwd = 'path/to/settings/cwd';
345+
setupSuccess(options, 'unittest', expected);
346+
await debugLauncher.launchDebugger(options);
347+
348+
debugService.verifyAll();
349+
});
350+
336351
test('Full debug config', async () => {
337352
const options: LaunchOptions = {
338353
cwd: 'one/two/three',

0 commit comments

Comments
 (0)