Reputation: 301
With pytest and vscode-python I would like to run tests which were previously implemented with the unittest framework.
Therefore, I successfully ran the tests using pytest in the respective directory tests
.
pytest
I also set up vscode-python and tested almost all tests succesfully.
However, those tests, which load data from the subdirectory tests/data
fail, because vscode-python seems to run pytest from another directory than the tests directory tests
.
abc/
|-- tests/
|-- test_function.py
|-- data/
How can I set up vscode-python, such that all data files from the already implemented tests are read successfully?
Upvotes: 15
Views: 22162
Reputation: 7282
In .vscode/settings.json
you can put
{
...
"python.testing.cwd": "${workspaceFolder}/tests",
}
Upvotes: 8
Reputation: 305
Navigate to "Settings" (in VS Code 1.35.0 on macOS):
Menu 'Code' >> 'Preferences' >> 'Settings'
In the 'Settings' pane, search for 'python.testing.cwd'.
The docs say that 'cwd' 'Specifies an optional working directory for unit tests.'
For your set-up, one way to generate a relative path for 'python.testing.cwd' would be to:
Alternatively, you may want to investigate specifying a path using one or more VS Code Variables.
References:
Upvotes: 14