0

We have a Python project that requires setting a PYTHONPATH relative to ${workspaceFolder}. We set it by adding an env block to our launch configuration, and specifying PYTHONPATH.

Unfortunately, our unit tests are not working well through VS Code in this case. We need to specify the path for unit tests as well. We can create an .env file and add the PYTHONPATH there, but we can't use ${workspaceFolder} there - it is not expanded. This leaves us with one option -specifying an absolute path in the .env file, which is not good (we can't add this file to git, for instance)

Is there any way to specify environment variables for tests in a way that expands ${workspaceFolder}? This is the kind of thing that PyCharm handles automatically without any issues, and it's quite frustrating.

zmbq
  • 38,013
  • 14
  • 101
  • 171
  • 2
    at the top of the unit test file, use `os.getcwd()` and `__file__` and modify `sys.path` or use the calculated path to adjust the files you are trying to locate, without a demonstration setup it is hard to help – rioV8 Jun 02 '22 at 13:39
  • Can this question help you? https://stackoverflow.com/questions/53653083/how-to-correctly-set-pythonpath-for-visual-studio-code – JialeDu Jun 06 '22 at 06:14

0 Answers0