Run/Debug config for unittests against vagrant box
已回答
I am able to run and debug against vagrant linux box but I am unable to get unittests to run properly. I am not sure about the configurations:
Pycharm 2018 is running on Windows 10, with linux vagrant box.
- Target script Path: I set to .
- Environment variables: PYTHONPATH to /opt/libraries where I have some custom libraries.
- Python Interpreter is the Remote Python3 on the Vagrant Vm
- Working Directory: /vagrant/path/dir where scripts being tested and tests directory is located.
- Path mappings: /users/MyUSER/documents/workspace/path to dir and then remote: same as working dir above.
I am getting ModuleNotFoundError for each of the tests files. Its obviously seeing the tests files in the tests dir but cant find them. Why?
Unit tests work perfectly when running python3 -m discover within working directory via ssh session.
Any ideas much appreciated. Vagrant will make working in windows bearable.
Thanks!
请先登录再写评论。
Hi John! It's hard to tell what's wrong exactly without the details, could you please specify the full ModuleNotFoundError traceback? Is it possible to run tests with right-click | Run? Please feel free to create a new ticket in our bug tracker: https://youtrack.jetbrains.com/issues/PY one can set a limited visibility there to ensure the privacy.
PY-29663
Problem resolved. Manually add sources root directory within your environments run config for PYTHONPATH instead of marking directory as sources root.
Marking the directory in Pycharm only works on the windows side and does not translate to the correct folder in vagrant.
Under the Python tests Run/Debug Configuration for your unittest add the following Environment variable:
PYTHONPATH=/vagrant/path/to/directory (where tests dir resides.)
If you have multiple PYTHONPATHS, just string them together with semi colon ;.