Python coverage always unknown


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/              0      0   100%
tests/       4      0   100%
tests/          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 recommend for pytest-cov (Python) , i.e. ^TOTAL.+?(\d+\%)$ which should work according to a regex checker.

regex expression

I also run coverage xml together with

        cobertura: coverage.xml

which results in a successful upload:

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

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

Hi @tlaber welcome to the forum and thanks for posting!

That should be working and coverage showing up on the job detail page as well as full jobs list, Merge Request and badge.

One thing that comes to mind is that prior to the 13.6 milestone the coverage badge would show “unknown” until the pipeline completed and then would populate the coverage value.

The coverage.xml does not populate this value today but is used by the Test Coverage Visualization feature.

Hopefully this helps!

-James H, GitLab Product Manager, Verify:Testing


Fortunately, one of our admins was able to help me referencing: CI/CD coverage is not able to capture coverage generated by pytest-cov (#48613) · Issues · / GitLab FOSS · GitLab

So in the end the regex didn’t fit even though it looks like it would.
The correct regex is:

and now it is working :slight_smile:


Glad to hear you got it working!

-James H, GitLab Product Manager, Verify:Testing

Thank you!