linux - 如何为 Gitlab 配置 Python coverage.pl 报告

标签 linux python-3.x gitlab-ci-runner coverage.py

我是 Gitlab 的新手,正在尝试为 Gitlab 设置覆盖率报告 -m。当我手动运行时,coverage report -m 会给我报告。只是不知道需要做什么才能在 Gitlab 上显示该内容。

这需要在 Linux for Gitlab 上运行 Python 3.6 单元测试代码覆盖率。

这是我的yml文件

stages: 
- build 
- test 
- coverage
- deploy

before_script:
  - python --version
  - pip install -r requirements.txt
  
unit-tests:  
 image:    
  name: "python:3.6" 
  entrypoint: [""]  
 stage: test  
 script: python3 -m unittest discover

test:
 image:   
  name: "python:3.6"
 stage: test
 script: 
   - PYTHONPATH=$(pwd) python3 my_Project_Lib/my_test_scripts/runner.py

coverage:
  stage: test
  script:
      #- docker pull $CONTAINER_TEST_IMAGE
      - python3 -m unittest discover
      #- docker run $CONTAINER_TEST_IMAGE /bin/bash -c "python -m coverage run tests/tests.py && python -m coverage report -m"
      
  coverage: '/TOTAL.+ ([0-9]{1,3}%)/'

这可以很好地运行我的单元测试和 runer.pl,但没有测试覆盖率数据。

最佳答案

以下是单元测试代码覆盖率的有效解决方案。

这是我的.yml-file

stages: 
- build 
- test 
- coverage
- deploy

before_script:
  - pip install -r requirements.txt

test:
 image:   
  name: "python:3.6"
 stage: test
 script: 
   - python my_Project_Lib/my_test_scripts/runner.py

unit-tests:
  stage: test
  script:
      - python -m unittest discover
      - coverage report -m
      - coverage-badge
      
  coverage: '/TOTAL.+ ([0-9]{1,3}%)/'

这运行我的单元测试和 runner.py 正常,也运行覆盖。您将需要在 requirements.txt

中执行以下操作
coverage
coverage-badge

还有 README.MD 中的这一行

[![coverage report](https://gitlab.your_link.com/your_user_name/your directory/badges/master/coverage.svg)](https://gitlab.your_link.com/your_user_name/your directory/commits/master)

您的用户名和链接可以从网址复制。

关于linux - 如何为 Gitlab 配置 Python coverage.pl 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56656726/

相关文章:

java - 无法从 linux 中的 eclipse juno 端口 80 启动 Apache tomcat

python - 无法从 Android 上的 Kivy 应用程序发送蓝牙

java - 如何在 Java 代码中调用 bash cmd "find -L"

Python time.time() -> IOError

html - 当多个div具有相同的类名但没有id标签时,如何使用BeautifulSoup选择特定的div?

python-3.x - Numpy.unique 在 .append 之后使用时失败

docker - GitLab:在构建镜像中挂载/builds 作为 tmpfs

python - Gitlab-CI 无法满足不可满足的约束 python missing

docker - GitLab CI Runner,如何在服务容器中使用卷或挂载

linux - 使用 Scheme for GIMP 编写矩阵转换