I use pytest. I have a "kernel" folder in the root of the project in which the file is located "ecommerce.py" Full path "./kernel/ecommerce.py" I have a unit test that should test this file it is in the path: "./test/test_ecommerce.py" How do I correctly specify the import of a file "ecommerce.py" in the test file?
project_root/
├── kernel/
│ └── ecommerce.py
└── test/
└── test_ecommerce.py
My attempts boiled down to the following:
from ..kernel.ecommerce import Ecommerce
and
from kernel.ecommerce import Ecommerce
and
os.path.dirname('/full/path/root_dir_project')
from kernel.ecommerce import Ecommerce
Despite the fact that the IDE sees the module correctly, py test itself cannot determine the kernel
ImportError while importing test module '/full/path/root_dir_project/kernel/test/test_ecommerce.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
kernel/test/test_ecommerce.py:7: in <module>
from ..kernel.ecommerce import Ecommerce
E ImportError: attempted relative import with no known parent package