python - 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。有什么想法吗?
解决方案
幸运的是,我的一个朋友能够提供帮助,参考:
https://gitlab.com/gitlab-org/gitlab-foss/-/issues/48613
所以最终regex
它不适合,即使它看起来像它。我想更困难的是另一个regex
是 Gitlab 本身推荐的。
正确的正则表达式是:
*TOTAL.*\s+(\d+%)$*
如您所见,与上述没有(视觉)差异......
推荐阅读
- angular - Angular 应用程序中的订阅未检索数据
- git - “远程分支”、“远程跟踪分支”和“跟踪分支”可以有不同的名称吗?
- php - 如何阻止 php curl 重写 cookie
- python - 使用 Python 编辑 xml 文件
- c# - AES 加密密钥
- typescript - 打字稿:是否可以将泛型类型评估为字符串文字?
- flutter - Flutter web:带有编辑器的文本字段
- angular - 如何在按钮单击时触发 Ctrl+z、Ctrl+y。我为此使用 Angular
- javascript - 通过 Javascript 加载 JSON 数据
- c# - 如何将excel文件保存到特定位置C#?