Skip to content
Advertisement

Python coverage in Gitlab CI not showing any percentages

I am trying to make test coverage work for a python project. And I simply cannot figure out why there is no percentage showing neither in the tests nor the badge.

The command coverage report is called produces this output in the log:

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

and depending on the regex-expression that is saved in General > CI/CD, it simply looks for the 88% next to TOTAL. I used the recommended one for pytest-cov (Python) , i.e. ^TOTAL.+?(d+%)$ which works according to a regex checker.

regex expression

I also run coverage xml together with

artifacts:
    reports:
        cobertura: coverage.xml

which results in a successful upload of the file but I dont think this would be necessary for showing the basic percentages:

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

Either way, it is not working for me using: GitLab Community Edition 12.10.11. Any ideas anyone?

Advertisement

Answer

Fortunately, a friend of mine was able to help, referencing:

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

So in the end the regex didn’t fit even though it looks like it would. I guess what made it even more difficult was the other regex was recommended by Gitlab itself.

The correct regex is: *TOTAL.*s+(d+%)$*

TOTAL.*s+(d+%)$

As you can see, there is no (visual) difference to the one above…

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement