I'm trying to set up a unit test coverage tool for one of the Python projects. I managed to script the GitLab CI YML file, but it runs into errors when triggered. Here is the error that I get:
ImportError while importing test module '/builds/user1/myProj/tests/test_run.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_run.py:12: in <module>
from data import prepare_data as pd
E ImportError: No module named 'data'
=========================== 1 error in 0.06 seconds ============================
In the test_run.py
, I have the following imports:
sys.path.append(os.path.abspath('../src'))
from data import prepare_data as pd
Here is my GitLab CI YML file:
- pip install -r requirements.txt
- python -m pytest -v --cov=myproj/ --cache-clear --color=yes tests/
I have the needed __init__.py
in the src folder. The src folder has a sub folder called data which I'm importing in my unit test as:
sys.path.append(os.path.abspath('../src'))
Is there something that I'm missing?