问题描述
我正在尝试使测试覆盖率适用于 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
并且根据保存在 General > CI/CD 中的 regex
表达式,它只是查找 88%
旁边的 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+%)$*
如您所见,与上面的没有(视觉)差异......
干杯!