Skip to content

Commit

Permalink
Force the pytest root dir to always be the workspace root. (#7803)
Browse files Browse the repository at this point in the history
(for #6548)
  • Loading branch information
ericsnowcurrently committed Oct 8, 2019
1 parent 5e9eaaf commit 9fe2a76
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/6548.md
@@ -0,0 +1 @@
Force the pytest root dir to always be the workspace root folder.
2 changes: 2 additions & 0 deletions src/client/testing/pytest/runner.ts
Expand Up @@ -51,6 +51,8 @@ export class TestManagerRunner implements ITestManagerRunner {
const testArgs = this.argsService.filterArguments(args, [JunitXmlArg]);
testArgs.splice(0, 0, `${JunitXmlArg}=${xmlLogFile}`);

testArgs.splice(0, 0, '--rootdir', options.workspaceFolder.fsPath);

// Positional arguments control the tests to be run.
testArgs.push(...testPaths);

Expand Down
1 change: 1 addition & 0 deletions src/client/testing/pytest/services/discoveryService.ts
Expand Up @@ -48,6 +48,7 @@ export class TestDiscoveryService implements ITestDiscoveryService {
if (args.indexOf('-s') === -1) {
args.splice(0, 0, '-s');
}
args.splice(0, 0, '--rootdir', options.workspaceFolder.fsPath);
return args;
}
protected async discoverTestsInTestDirectory(options: TestDiscoveryOptions): Promise<Tests> {
Expand Down
19 changes: 16 additions & 3 deletions src/test/testing/pytest/services/discoveryService.unit.test.ts
Expand Up @@ -102,7 +102,11 @@ suite('Unit Tests - PyTest - Discovery', () => {
};

const filteredArgs = options.args;
const expectedArgs = ['-s', ...filteredArgs];
const expectedArgs = [
'--rootdir', __dirname,
'-s',
...filteredArgs
];
when(argsService.filterArguments(deepEqual(options.args), TestFilter.discovery)).thenReturn(filteredArgs);

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

const filteredArgs = options.args;
const expectedArgs = ['-s', ...filteredArgs];
const expectedArgs = [
'--rootdir', __dirname,
'-s',
...filteredArgs
];
when(argsService.filterArguments(deepEqual(options.args), TestFilter.discovery)).thenReturn(filteredArgs);

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

const filteredArgs = options.args;
const expectedArgs = ['-s', '--cache-clear', ...filteredArgs];
const expectedArgs = [
'--rootdir', __dirname,
'-s',
'--cache-clear',
...filteredArgs
];
when(argsService.filterArguments(deepEqual(options.args), TestFilter.discovery)).thenReturn(filteredArgs);

const args = discoveryService.buildTestCollectionArgs(options);
Expand Down

0 comments on commit 9fe2a76

Please sign in to comment.