Skip to content

Commit 9bd380a

Browse files
committed
Generate standard code coverage report data file in python:test task
The `coverage run` command used to run the Python unit tests generates a `.coverage` data file. This file can not be consumed directly by the "codecov/codecov-action" GitHub Actions action that uploads the coverage data to Codecov. A separate `coverage xml` command must be used to generate the appropriate file. Previously this `coverage xml` command was ran directly in the test runner GitHub Actions workflow. However, the file is also required by contributors running tests on their local machines in some cases (e.g., displaying coverage in the VS Code editor via the popular "Coverage Gutters" extension, which does not support the `.coverage` file). For this reason, it is best to move the `coverage xml` command invocation to the taskfile. The time required to generate the file is insignificant so it is added to the `python:test` task rather than adding a separate task the contributor would be required to run after the `python:test` task.
1 parent c3a24a4 commit 9bd380a

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

.github/workflows/test-python-poetry-task.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ jobs:
7272
permissions:
7373
contents: read
7474

75-
env:
76-
COVERAGE_DATA_FILENAME: coverage.xml
77-
7875
steps:
7976
- name: Checkout repository
8077
uses: actions/checkout@v4
@@ -102,14 +99,6 @@ jobs:
10299
- name: Display code coverage report
103100
run: task python:coverage-report
104101

105-
# codecov/codecov-action only makes the conversion if the `coverage` package is installed in the global runner
106-
# environment
107-
- name: Convert code coverage report to format required by Codecov
108-
run: |
109-
poetry run \
110-
coverage xml \
111-
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
112-
113102
# A token is used to avoid intermittent spurious job failures caused by rate limiting.
114103
- name: Set up Codecov upload token
115104
run: |
@@ -128,5 +117,5 @@ jobs:
128117
uses: codecov/codecov-action@v3
129118
with:
130119
fail_ci_if_error: true
131-
file: ${{ env.COVERAGE_DATA_FILENAME }}
120+
file: coverage.xml
132121
token: ${{ env.CODECOV_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/node_modules/
22
__pycache__/
33
.coverage
4+
/coverage.xml

Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ tasks:
272272
--source="{{.PYTHON_PROJECT_PATH}}" \
273273
--module \
274274
pytest "{{.PYTHON_PROJECT_PATH}}/tests"
275+
- |
276+
poetry run \
277+
coverage xml
275278
276279
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
277280
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml

0 commit comments

Comments
 (0)