From ea855f05d7580dde199f429fd2c5704f1e084c91 Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Mon, 4 Nov 2024 11:28:01 -0800 Subject: [PATCH] add python.testing.cwd to pytest discovery if present --- .../testController/pytest/pytestDiscoveryAdapter.ts | 3 +++ .../pytest/pytestDiscoveryAdapter.unit.test.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts index e62bd02dd3de..b9565971f0da 100644 --- a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts +++ b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts @@ -84,6 +84,9 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { traceWarn("Symlink found, adding '--rootdir' to pytestArgs only if it doesn't already exist. cwd: ", cwd); pytestArgs = addValueIfKeyNotExist(pytestArgs, '--rootdir', cwd); } + // if user has provided `--rootdir` then use that, otherwise add `cwd` + // root dir is required so pytest can find the relative paths and for symlinks + addValueIfKeyNotExist(pytestArgs, '--rootdir', cwd); // get and edit env vars const mutableEnv = { diff --git a/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts b/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts index 87b91f6ae2da..ddd44835be48 100644 --- a/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts +++ b/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts @@ -179,7 +179,17 @@ suite('pytest test discovery adapter', () => { // verification - const expectedArgs = ['-m', 'pytest', '-p', 'vscode_pytest', '--collect-only', '.', 'abc', 'xyz']; + const expectedArgs = [ + '-m', + 'pytest', + '-p', + 'vscode_pytest', + '--collect-only', + '.', + 'abc', + 'xyz', + `--rootdir=${expectedPathNew}`, + ]; execService.verify( (x) => x.execObservable(