Running modules as scripts
I need some help running modules as stand alone scripts. Let's assume I have the following folder layout:
- my_package
- __init__.py
- Workers
- worker_monitor.py
- worker_process.py
- WorkersTest
- __init__.py
- worker_test.py
- test_data.dat
- Workers
- __init__.py
In the following directory structure, worker_test.py is the unit test module for worker_monitor and worker_process. Now, I can execute worker_test.py fine from within PyCharm (PyCharm is totally awesome here!) I am struggling to run this test from the command line.
If I run the tests from WorkersTest/, I get the error "ImportError: No module named my_package.Workers.worker_monitor". I'm assuming that PyCharm successfully runs the tests because it applies some magic to the paths.
I would like to know what magic is being applied? Thanks.
请先登录再写评论。
PyCharm adds the root directory of the project to the PYTHONPATH environment variable.
Simple and it works handsomely.
Thanks Dmitry.