简体   繁体   中英

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM