Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit test coverage with GitLab CI

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?

like image 864
joesan Avatar asked Nov 07 '22 06:11

joesan


1 Answers

I managed to fix this error by completely moving to another test coverage Python package. Here is my GitLab CI yml configuration that prints the coverage report upon even run by GitLab:

- nosetests --with-coverage --cover-erase --cover-package=tests/ --cover-html

This just works like I expected it to be!

like image 146
joesan Avatar answered Nov 14 '22 21:11

joesan