Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python GitLab CI的单元测试覆盖率_Python_Unit Testing_Gitlab Ci_Pytest Cov - Fatal编程技术网

Python GitLab CI的单元测试覆盖率

Python GitLab CI的单元测试覆盖率,python,unit-testing,gitlab-ci,pytest-cov,Python,Unit Testing,Gitlab Ci,Pytest Cov,我正在尝试为一个Python项目设置一个单元测试覆盖率工具。我设法编写了GitLab CI YML文件的脚本,但在触发时遇到了错误。以下是我得到的错误: 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_r

我正在尝试为一个Python项目设置一个单元测试覆盖率工具。我设法编写了GitLab CI YML文件的脚本,但在触发时遇到了错误。以下是我得到的错误:

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 ============================
这是我的GitLab CI YML文件:

- pip install -r requirements.txt
- python -m pytest -v --cov=myproj/ --cache-clear --color=yes tests/
我在src文件夹中有所需的
\uuuu init\uuuu.py
。src文件夹有一个名为data的子文件夹,我在单元测试中将其导入为:

sys.path.append(os.path.abspath('../src'))

有什么我遗漏的吗?

我通过完全转移到另一个测试覆盖率Python包来修复这个错误。下面是我的GitLab CI yml配置,它在GitLab运行时打印覆盖率报告:

- nosetests --with-coverage --cover-erase --cover-package=tests/ --cover-html
这就像我期望的那样

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