gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:49:00 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com