Note that the test did not pass with Import Error in the existing project
When the project structure is as follows
root/
├ module/
│ └ submodule/
│ └ to_import_module
└ tests/
└ test1.py
Trying to import to_import_module in test1.py
import module.submoule.to_import_module
Even as
#### **` No module named to_import_module`**
```importerror
Will be pushed back. However, for this reason, I specified a path
It's also a hassle to change project settings and so on.
So here I use sys and os modules
import os import sys sys.path.append(os.path.dirname(os.path.abspath(file)) + '/../module/submodule') import to_import_module
Import becomes possible by expanding the exploration path range.
It is good to specify a relative path so that it works in other environments.
However, this method makes me angry with "pep8 E402",
** Test execution is heavier than code rules **
So please forgive me.
Of course, it is NG to use for the favorite code
Recommended Posts