# Python coverage always unknown

**URL:** <https://forum.gitlab.com/t/python-coverage-always-unknown/47819>\
**Category:** GitLab CI/CD\
**Tags:** ci, test, python\
**Created:** [January 21, 2021, 5:14am UTC](https://forum.gitlab.com/t/python-coverage-always-unknown/47819 "2021-01-21T05:14:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlaber](https://avatars.discourse-cdn.com/v4/letter/t/cab0a1/32.png) [@tlaber](https://forum.gitlab.com/u/tlaber)\
**Post date:** [January 21, 2021, 5:14am UTC](https://forum.gitlab.com/t/python-coverage-always-unknown/47819/1 "2021-01-21T05:14:09Z")

</div>

Hey,

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:

```auto
[...]
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 recommend for _pytest-cov (Python)_ , i.e. `^TOTAL.+?(\d+\%)$` which should work according to a regex checker.

[![regex expression](https://i.stack.imgur.com/z4Yka.png)](https://i.stack.imgur.com/z4Yka.png)

I also run `coverage xml` together with

```auto
artifacts:
    reports:
        cobertura: coverage.xml

```

which results in a successful upload:

```auto
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?

---

<div class="post-metadata">

**Author:** ![jheimbuck\_gl](https://sea2.discourse-cdn.com/gitlab/user_avatar/forum.gitlab.com/jheimbuck_gl/32/8112_2.png) [@jheimbuck\_gl](https://forum.gitlab.com/u/jheimbuck_gl)\
**Post date:** [January 21, 2021, 4:33pm UTC](https://forum.gitlab.com/t/python-coverage-always-unknown/47819/2 "2021-01-21T16:33:57Z")

</div>

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](https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html).

Hopefully this helps!

-James H, GitLab Product Manager, Verify:Testing

---

<div class="post-metadata">

**Author:** ![tlaber](https://avatars.discourse-cdn.com/v4/letter/t/cab0a1/32.png) [@tlaber](https://forum.gitlab.com/u/tlaber)\
**Post date:** [January 22, 2021, 7:39am UTC](https://forum.gitlab.com/t/python-coverage-always-unknown/47819/3 "2021-01-22T07:39:12Z")

</div>

Hello.

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.org / GitLab FOSS · GitLab](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.  
The correct regex is:  
`*TOTAL.*\s+(\d+%)$*`

and now it is working 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![jheimbuck\_gl](https://sea2.discourse-cdn.com/gitlab/user_avatar/forum.gitlab.com/jheimbuck_gl/32/8112_2.png) [@jheimbuck\_gl](https://forum.gitlab.com/u/jheimbuck_gl)\
**Post date:** [January 22, 2021, 12:29pm UTC](https://forum.gitlab.com/t/python-coverage-always-unknown/47819/4 "2021-01-22T12:29:39Z")

</div>

Glad to hear you got it working!

-James H, GitLab Product Manager, Verify:Testing

---

<div class="post-metadata">

**Author:** ![tlaber](https://avatars.discourse-cdn.com/v4/letter/t/cab0a1/32.png) [@tlaber](https://forum.gitlab.com/u/tlaber)\
**Post date:** [January 22, 2021, 12:56pm UTC](https://forum.gitlab.com/t/python-coverage-always-unknown/47819/5 "2021-01-22T12:56:34Z")

</div>

Thank you!
