Skip to content

Commit dc46eb5

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 494d528 commit dc46eb5

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ jobs:
6565
if: needs.run-determination.outputs.result == 'true'
6666
runs-on: ubuntu-latest
6767

68-
env:
69-
COVERAGE_DATA_FILENAME: coverage.xml
70-
7168
steps:
7269
- name: Checkout repository
7370
uses: actions/checkout@v4
@@ -98,14 +95,6 @@ jobs:
9895
- name: Display code coverage report
9996
run: task python:coverage-report
10097

101-
# codecov/codecov-action only makes the conversion if the `coverage` package is installed in the global runner
102-
# environment
103-
- name: Convert code coverage report to format required by Codecov
104-
run: |
105-
poetry run \
106-
coverage xml \
107-
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
108-
10998
# A token is used to avoid intermittent spurious job failures caused by rate limiting.
11099
- name: Set up Codecov upload token
111100
run: |
@@ -124,5 +113,5 @@ jobs:
124113
uses: codecov/codecov-action@v3
125114
with:
126115
fail_ci_if_error: true
127-
file: ${{ env.COVERAGE_DATA_FILENAME }}
116+
file: coverage.xml
128117
token: ${{ env.CODECOV_TOKEN }}

Taskfile.yml

+3
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ tasks:
439439
--source="{{.PYTHON_PROJECT_PATH}}" \
440440
--module \
441441
pytest "{{.PYTHON_PROJECT_PATH}}/tests"
442+
- |
443+
poetry run \
444+
coverage xml
442445
443446
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
444447
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml

0 commit comments

Comments
 (0)