You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running a test with a settings.json that contains the "python.testing.cwd": "root/dir" option should result in a pytest command that uses "root/dir" as the --rootdir argument. If it is null, then fallback to existing behavior: --rootdir ${workspaceFolder}.
This is necessary for my use case since my code is in a monorepo and loads test fixtures from disk using paths relative to a project root rather than the repo root.
The "python.testing.cwd" setting has no visible effect on --rootdir. It is always the "workspace folder", which makes sense given the code I linked to below.
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
Open a workspace folder containing python tests that are not in the root directory (i.e. a monorepo).
Configure pytest to test a project directory.
2a. configure "python.testing.cwd" in settings.json to the project root.
Discover tests and observe that all tests are discovered.
Run all tests.
4a. Observe the test session starts and all tests pass that do not need to load fixtures from disk.
4b. Observe the output logs look like this:
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
XXX
Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)
Environment data
"python.jediEnabled"set to; more info How to update the language server to the latest stable version #3977): Language ServerExpected behaviour
When running a test with a
settings.jsonthat contains the"python.testing.cwd": "root/dir"option should result in a pytest command that uses"root/dir"as the--rootdirargument. If it isnull, then fallback to existing behavior:--rootdir ${workspaceFolder}.This is necessary for my use case since my code is in a monorepo and loads test fixtures from disk using paths relative to a project root rather than the repo root.
For example,
jfyi, I've anonymized
[~]and[...testfolders].Actual behaviour
The
"python.testing.cwd"setting has no visible effect on--rootdir. It is always the "workspace folder", which makes sense given the code I linked to below.Relevant Code
vscode-python/src/client/testing/pytest/services/discoveryService.ts
Line 53 in 2b6a8f2
vscode-python/src/client/testing/pytest/main.ts
Lines 50 to 52 in 2b6a8f2
vscode-python/src/client/testing/pytest/main.ts
Lines 19 to 20 in 2b6a8f2
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
2a. configure "python.testing.cwd" in settings.json to the project root.
4a. Observe the test session starts and all tests pass that do not need to load fixtures from disk.
4b. Observe the output logs look like this:
Logs
Output for
Pythonin theOutputpanel (View→Output, change the drop-down the upper-right of theOutputpanel toPython)Output from
Consoleunder theDeveloper Toolspanel (toggle Developer Tools on underHelp; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging)