Skip to content

Commit 9fe2a76

Browse files
Force the pytest root dir to always be the workspace root. (#7803)
(for #6548)
1 parent 5e9eaaf commit 9fe2a76

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

news/2 Fixes/6548.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Force the pytest root dir to always be the workspace root folder.

src/client/testing/pytest/runner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export class TestManagerRunner implements ITestManagerRunner {
5151
const testArgs = this.argsService.filterArguments(args, [JunitXmlArg]);
5252
testArgs.splice(0, 0, `${JunitXmlArg}=${xmlLogFile}`);
5353

54+
testArgs.splice(0, 0, '--rootdir', options.workspaceFolder.fsPath);
55+
5456
// Positional arguments control the tests to be run.
5557
testArgs.push(...testPaths);
5658

src/client/testing/pytest/services/discoveryService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class TestDiscoveryService implements ITestDiscoveryService {
4848
if (args.indexOf('-s') === -1) {
4949
args.splice(0, 0, '-s');
5050
}
51+
args.splice(0, 0, '--rootdir', options.workspaceFolder.fsPath);
5152
return args;
5253
}
5354
protected async discoverTestsInTestDirectory(options: TestDiscoveryOptions): Promise<Tests> {

src/test/testing/pytest/services/discoveryService.unit.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ suite('Unit Tests - PyTest - Discovery', () => {
102102
};
103103

104104
const filteredArgs = options.args;
105-
const expectedArgs = ['-s', ...filteredArgs];
105+
const expectedArgs = [
106+
'--rootdir', __dirname,
107+
'-s',
108+
...filteredArgs
109+
];
106110
when(argsService.filterArguments(deepEqual(options.args), TestFilter.discovery)).thenReturn(filteredArgs);
107111

108112
const args = discoveryService.buildTestCollectionArgs(options);
@@ -121,7 +125,11 @@ suite('Unit Tests - PyTest - Discovery', () => {
121125
};
122126

123127
const filteredArgs = options.args;
124-
const expectedArgs = ['-s', ...filteredArgs];
128+
const expectedArgs = [
129+
'--rootdir', __dirname,
130+
'-s',
131+
...filteredArgs
132+
];
125133
when(argsService.filterArguments(deepEqual(options.args), TestFilter.discovery)).thenReturn(filteredArgs);
126134

127135
const args = discoveryService.buildTestCollectionArgs(options);
@@ -140,7 +148,12 @@ suite('Unit Tests - PyTest - Discovery', () => {
140148
};
141149

142150
const filteredArgs = options.args;
143-
const expectedArgs = ['-s', '--cache-clear', ...filteredArgs];
151+
const expectedArgs = [
152+
'--rootdir', __dirname,
153+
'-s',
154+
'--cache-clear',
155+
...filteredArgs
156+
];
144157
when(argsService.filterArguments(deepEqual(options.args), TestFilter.discovery)).thenReturn(filteredArgs);
145158

146159
const args = discoveryService.buildTestCollectionArgs(options);

0 commit comments

Comments
 (0)