首页 > 解决方案 > Gitlab CI 中的 Python 覆盖率未显示任何百分比

问题描述

我正在尝试使测试覆盖率适用于 python 项目。而且我根本无法弄清楚为什么在测试和徽章中都没有显示百分比。

调用该命令coverage report会在日志中产生以下输出:

[...]
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

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

正则表达式

我也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。有什么想法吗?

标签: pythoncode-coveragegitlab-cicoverage.py

解决方案


幸运的是,我的一个朋友能够提供帮助,参考:

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

所以最终regex它不适合,即使它看起来像它。我想更困难的是另一个regex是 Gitlab 本身推荐的。

正确的正则表达式是: *TOTAL.*\s+(\d+%)$*

总计.*\s+(\d+%)$

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


推荐阅读