Pain with Python and Coverage

Hi,

I want to achieve something that should be, or used to be, simple: I want to have coverage reports in my build report pages, preferably like those mentioned on this page:

I tried all combinations of parameters between pytest-cov and Jenkins’ Coverage plugin that I could think of, but to no avail. Trying to use the code snippet from the documentation page even failed with some parameter error for the qualityGates. In the future, I would like to expand coverage testing to other languages, too, but at the moment, I am quite lost and would much appreciate pointers to relevant documentation or code.

Thank you!

My Jenkins setup:

Jenkins: 2.488
OS: Linux - 6.1.0-17-amd64
Java: 17.0.14 - Debian (OpenJDK 64-Bit Server VM)
---
antisamy-markup-formatter:173.v680e3a_b_69ff3
apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83
apache-httpcomponents-client-5-api:5.4-136.v5a_21779c63f8
asm-api:9.7.1-97.v4cc844130d97
authentication-tokens:1.131.v7199556c3004
blueocean:1.27.16
blueocean-bitbucket-pipeline:1.27.16
blueocean-commons:1.27.16
blueocean-config:1.27.16
blueocean-core-js:1.27.16
blueocean-dashboard:1.27.16
blueocean-display-url:2.4.3
blueocean-events:1.27.16
blueocean-git-pipeline:1.27.16
blueocean-github-pipeline:1.27.16
blueocean-i18n:1.27.16
blueocean-jwt:1.27.16
blueocean-personalization:1.27.16
blueocean-pipeline-api-impl:1.27.16
blueocean-pipeline-editor:1.27.16
blueocean-pipeline-scm-api:1.27.16
blueocean-rest:1.27.16
blueocean-rest-impl:1.27.16
blueocean-web:1.27.16
bootstrap5-api:5.3.3-2
bouncycastle-api:2.30.1.80-256.vf98926042a_9b_
branch-api:2.1214.v3f652804588d
caffeine-api:3.2.0-161.v691ef352cee1
checks-api:367.v18b_7f530e54a_
cloud-stats:377.vd8a_6c953e98e
cloudbees-bitbucket-branch-source:935.0.0
cloudbees-folder:6.982.vf165a_16c9507
command-launcher:118.v72741845c17a_
commons-compress-api:1.26.1-2
commons-lang3-api:3.17.0-84.vb_b_938040b_078
commons-text-api:1.13.0-153.v91dcd89e2a_22
configuration-as-code:1932.v75cb_b_f1b_698d
coverage:2.2.0
credentials:1408.va_622a_b_f5b_1b_1
credentials-binding:687.v619cb_15e923f
data-tables-api:2.2.2-1
display-url-api:2.209.v582ed814ff2f
docker-commons:445.v6b_646c962a_94
docker-java-api:3.4.1-96.v77147a_de67f8
docker-plugin:1.10.0
durable-task:581.v299a_5609d767
echarts-api:5.6.0-2
eddsa-api:0.3.0-13.v7cb_69ed68f00
favorite:2.225.v68765b_b_a_1fa_3
font-awesome-api:6.7.2-1
forensics-api:3.0.0
git:5.7.0
git-client:6.1.2
gitea:238.v626a_cf5e1940
gitea-checks:514.v71a_4889b_16d6
github:1.42.0
github-api:1.321-478.vc9ce627ce001
github-branch-source:1810.v913311241fa_9
groovy:497.v7b_061a_a_de65d
gson-api:2.12.1-113.v347686d6729f
handy-uri-templates-2-api:2.1.8-36.v85e4cb_234a_13
htmlpublisher:424.va_e57f1253461
instance-identity:201.vd2a_b_5a_468a_a_6
ionicons-api:82.v0597178874e1
jackson2-api:2.17.0-389.va_5c7e45cd806
jakarta-activation-api:2.1.3-2
jakarta-mail-api:2.1.3-2
javax-activation-api:1.2.0-8
javax-mail-api:1.6.2-11
jaxb:2.3.9-133.vb_ec76a_73f706
jdk-tool:83.v417146707a_3d
jenkins-design-language:1.27.16
jjwt-api:0.11.5-120.v0268cf544b_89
joda-time-api:2.13.1-115.va_6b_5f8efb_1d8
jquery3-api:3.7.1-3
json-api:20250107-125.v28b_a_ffa_eb_f01
json-path-api:2.9.0-148.v22a_7ffe323ce
jsoup:1.18.3-30.v952e9442d416
junit:1317.v5b_35d792b_06a_
mailer:489.vd4b_25144138f
matrix-project:845.vffd7fa_f27555
mina-sshd-api-common:2.14.0-143.v2b_362fc39576
mina-sshd-api-core:2.14.0-143.v2b_362fc39576
okhttp-api:4.11.0-183.va_87fc7a_89810
people-view:1.2
pipeline-build-step:555.v589d5c24a_3d6
pipeline-graph-analysis:231.v56354571a_da_0
pipeline-groovy-lib:752.vdddedf804e72
pipeline-input-step:515.v8857b_eb_b_910c
pipeline-milestone-step:127.vb_52887ca_3b_6d
pipeline-model-api:2.2234.v4a_b_13b_8cd590
pipeline-model-definition:2.2234.v4a_b_13b_8cd590
pipeline-model-extensions:2.2234.v4a_b_13b_8cd590
pipeline-stage-step:322.vecffa_99f371c
pipeline-stage-tags-metadata:2.2234.v4a_b_13b_8cd590
plain-credentials:183.va_de8f1dd5a_2b_
plugin-util-api:6.0.0
prism-api:1.29.0-19
pubsub-light:1.18
pyenv-pipeline:2.1.2
role-strategy:756.v978cb_392eb_d3
scm-api:704.v3ce5c542825a_
script-security:1373.vb_b_4a_a_c26fa_00
snakeyaml-api:2.3-123.v13484c65210a_
sse-gateway:1.27
ssh-credentials:349.vb_8b_6b_9709f5b_
ssh-slaves:3.1031.v72c6b_883b_869
sshd:3.353.v2b_d33c46e970
structs:343.vdcf37b_a_c81d5
token-macro:444.v52de7e9c573d
trilead-api:2.192.vc50a_d147e369
variant:70.va_d9f17f859e0
workflow-api:1363.v03f731255494
workflow-basic-steps:1079.vce64b_a_929c5a_
workflow-cps:4018.vf02e01888da_f
workflow-durable-task-step:1405.v1fcd4a_d00096
workflow-job:1505.vea_4b_20a_4a_495
workflow-multibranch:803.v08103b_87c280
workflow-scm-step:437.v05a_f66b_e5ef8
workflow-step-api:700.v6e45cb_a_5a_a_21
workflow-support:961.v51869f7b_d409

In my setup I start pytest with --cov-report xml, this produces the file test/coverage.xml
I then collect the coverage with

recordCoverage enabledForFailure: true, tools: [[parser: 'COBERTURA', pattern: 'test/coverage.xml']]

Hi Markus,

that was a huge step forward already, although this didn’t work the same way for me. Maybe you have different versions, but I needed:

pytest -s --black --cov-report xml:tests/coverage.xml --cov appdir # NOT “.”!

The key issue was the ‘pattern’ parameter to the function call.

Is there a good reference, please, where to read up all the nitty-gritty details of what I can do and not do in a pipeline?

Thank you!

On each pipeline job you have a link in the sidepanel Pipeline Syntax. This opens the snippetizer where you can select a step and configure it with all possible parameters. Well maintained plugins have then corresponding help files so you get the ? that you can click and get an explanation of what that particular field will do.

Thank you! I didn’t notice it because I am writing the pipelines in a Jenkinsfile.