I have the following folder structure for my Python project (in Pycharm):
Tool
|___Script
|___logs
|___ tests
| |___setA
| |___setB
| |___setC
| |___testSetC.py
|___ __init__.py
|______script.py
and I'm trying to import methods defined in script.py
in testSetC.py
.
I have from Script.script import *
at the top of testSetC.py
and the script runs without any issues inside Pycharm
. However, when I tried to run the same from the command line, it failed with the error message ModuleNotFoundError: No module named 'Script'
.
I poked around and found that Pycharm's run configuration automatically adds the Tool
directory to PYTHONPATH
essentially masking the error.
What is the correct way to do this without manually amending sys.path
in every test script? It looks hackish IMO.