我正在尝试使测试覆盖率适用于 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+\%)$
,它根据正则表达式检查器工作。
我还运行 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+%)$*
如您所见,与上面的没有(视觉)差异......
关于Gitlab CI 中的 Python 覆盖率未显示任何百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65821603/