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?
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With