[pytest] If present, "python.testing.cwd" expected to change `pytest --rootdir` arg value.
See original GitHub issueEnvironment data
- VS Code version: 1.41.0
- Extension version (available under the Extensions sidebar): 2020.1.57204
- OS and version: MacOS 10.14.6
- Python version (& distribution if applicable, e.g. Anaconda): 3.7
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
- Relevant/affected Python packages and their versions: pytest-5.2.2
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): Language Server
Expected behaviour
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.
For example,
python [~]/.vscode/extensions/ms-python.python-2020.1.57204/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir root/dir -s --cache-clear [...testfolders]
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
Steps to reproduce:
[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:
python [~]/.vscode/extensions/ms-python.python-2020.1.57204/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir [workspaceFolder] -s --cache-clear [project dir]
============================= test session starts ==============================
platform darwin -- Python 3.7.6, pytest-5.2.2, py-1.8.1, pluggy-0.13.1
rootdir: [workspaceFolder]
plugins: doubles-1.5.3, cov-2.8.1
Logs
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
)
XXX
Issue Analytics
- State:
- Created 4 years ago
- Reactions:24
- Comments:17 (5 by maintainers)
Couldn’t this be fixed by removing
--rootdir
fromoptionsWithArgsToRemove
?This way if people wish to override the arg they can.
There is issue in our company we use old pytest v3 and giving --rootdir param is causing problems that we cannot use pytest discovery module. Please add option
"python.testing.cwd": null
to completely remove --rootdir parameter!