I want to run the test if started via Visual Studio Code in the same directory as started from command line with pytest tests
.
The folder structure is as follows:
project-root
|- .vscode
- settings.json
|-data-processing
| |-src
| |-tests
I run pytest from data-processing
folder pytest tests
with os.getcwd()
yielding:
...project-root/data-processing
If I run from VS Code os.getcwd()
yields:
...project-root
With this setup (settings.json
):
{
"python.testing.pytestArgs": [
"data-processing/tests",
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
I tried to use python.testing.cwd
option to set working directory:
{
"python.testing.pytestArgs": [
"tests",
],
"python.testing.cwd": "./data-processing/",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
The problem is as soon as I set cwd
the test discovery stops working – no test discovered at all. I tried different paths with and without “./”. I also checked microsoft/vscode-python#22504.
So how to get the same working directory in VS Code for test runs? Changing the directory with os.chdir
is not working since my problem is due to module resolution from within pyspark.