【问题标题】:How to configure Python coverage.pl report for Gitlab如何为 Gitlab 配置 Python coverage.pl 报告
【发布时间】:2019-06-18 20:39:08
【问题描述】:

我是 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,但没有测试覆盖率数据。

【问题讨论】:

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


    【解决方案1】:

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

    这是我的.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)
    

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

    【讨论】:

      猜你喜欢
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多