Gitlab CI 中的 Python 覆盖率未显示任何百分比

标签 python code-coverage gitlab-ci coverage.py

我正在尝试使测试覆盖率适用于 python 项目。我根本不明白为什么测试和徽章中都没有显示百分比。

调用命令覆盖率报告会在日志中生成以下输出:

[...]
tests/__init__.py              0      0   100%
tests/test_ml_squarer.py       4      0   100%
tests/test_squarer.py          4      0   100%
----------------------------------------------
TOTAL                         17      2    88%
test_service run-test: commands[4] | coverage xml

并且根据 General > CI/CD 中保存的 regex 表达式,它只是查找旁边的 88% 总计。我使用了推荐的 pytest-cov (Python) ,即 ^TOTAL.+?(\d+\%)$ ,它根据正则表达式检查器工作。

regex expression

我还运行 coverage xml 以及

artifacts:
    reports:
        cobertura: coverage.xml

这会导致文件成功上传,但我认为这对于显示基本百分比来说不是必需的:

Uploading artifacts...
Runtime platform                                    arch=amd64 os=linux pid=29421 revision=05161b14 version=12.4.1
coverage.xml: found 1 matching files               
Uploading artifacts to coordinator... ok            id=8996 responseStatus=201 Created token=DXpxsGiF

无论如何,它对我来说不起作用:GitLab Community Edition 12.10.11。大家有什么想法吗?

最佳答案

幸运的是,我的一位 friend 能够提供帮助,引用:

https://gitlab.com/gitlab-org/gitlab-foss/-/issues/48613

所以最终正则表达式不适合,尽管看起来很适合。我猜让事情变得更加困难的是 Gitlab 本身推荐的另一个 regex

正确的正则表达式是: *总计。*\s+(\d+%)$*

TOTAL.*\s+(\d+%)$

如您所见,与上面的没有(视觉)差异......

关于Gitlab CI 中的 Python 覆盖率未显示任何百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65821603/

相关文章:

gitlab - 生成 gitlab ci 工件作为 native 文件类型

gitlab - .gitlab-ci.yml 中的 `cache:key` 有什么意义?

python - mypy 会检查“从不键入”吗?

Python 每个列表中一项的所有组合

PHPstorm PHPunit 代码共同覆盖

testing - 如何从我的 Golang 服务器获取代码覆盖率?

python - 如何从 Django 模型(覆盖) save( ) 函数向 View 发送警报或消息?

python - 无法在 Windows 上安装 cv2

java - 如何将连体衣集成到开源项目中?

git - 使用语义发布生成版本标签,不带 v