Skip to content

Commit 622653e

Browse files
authored
add python.testing.cwd to pytest discovery if present (#24384)
fixes #9553
1 parent 379229a commit 622653e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter {
8484
traceWarn("Symlink found, adding '--rootdir' to pytestArgs only if it doesn't already exist. cwd: ", cwd);
8585
pytestArgs = addValueIfKeyNotExist(pytestArgs, '--rootdir', cwd);
8686
}
87+
// if user has provided `--rootdir` then use that, otherwise add `cwd`
88+
// root dir is required so pytest can find the relative paths and for symlinks
89+
addValueIfKeyNotExist(pytestArgs, '--rootdir', cwd);
8790

8891
// get and edit env vars
8992
const mutableEnv = {

src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,17 @@ suite('pytest test discovery adapter', () => {
179179

180180
// verification
181181

182-
const expectedArgs = ['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only', '.', 'abc', 'xyz'];
182+
const expectedArgs = [
183+
'-m',
184+
'pytest',
185+
'-p',
186+
'vscode_pytest',
187+
'--collect-only',
188+
'.',
189+
'abc',
190+
'xyz',
191+
`--rootdir=${expectedPathNew}`,
192+
];
183193
execService.verify(
184194
(x) =>
185195
x.execObservable(

0 commit comments

Comments
 (0)