Skip to content

Commit b150f3b

Browse files
authored
Don't override user provided --rootdir in pytest args. (#17509)
1 parent 2be940b commit b150f3b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

news/2 Fixes/8678.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't override user provided `--rootdir` in pytest args.

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ function pytestFilterArguments(args: string[], argumentToRemoveOrFilter: string[
217217
'--verbosity',
218218
'-r',
219219
'--tb',
220-
'--rootdir',
221220
'--show-capture',
222221
'--durations',
223222
'--junit-xml',
@@ -277,6 +276,10 @@ export function preparePytestArgumentsForDiscovery(options: TestDiscoveryOptions
277276
if (args.indexOf('-s') === -1) {
278277
args.splice(0, 0, '-s');
279278
}
280-
args.splice(0, 0, '--rootdir', options.workspaceFolder.fsPath);
279+
280+
// Only add --rootdir if user has not already provided one
281+
if (args.filter((a) => a.startsWith('--rootdir')).length === 0) {
282+
args.splice(0, 0, '--rootdir', options.cwd);
283+
}
281284
return args;
282285
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ export class PytestRunner implements ITestsRunner {
8686
// Ensure that we use the xunit1 format.
8787
testArgs.splice(0, 0, '--override-ini', 'junit_family=xunit1');
8888

89-
// Make sure root dir is set so pytest can find the relative paths
90-
testArgs.splice(0, 0, '--rootdir', options.workspaceFolder.fsPath);
89+
// if user has provided `--rootdir` then use that, otherwise add `cwd`
90+
if (testArgs.filter((a) => a.startsWith('--rootdir')).length === 0) {
91+
// Make sure root dir is set so pytest can find the relative paths
92+
testArgs.splice(0, 0, '--rootdir', options.workspaceFolder.fsPath);
93+
}
9194

9295
// Positional arguments control the tests to be run.
9396
const rawData = idToRawData.get(testNode.id);

0 commit comments

Comments
 (0)