This action analyses the pytest result files and publishes the report as a comment on a pull requests.
permissions:
contents: read
pull-requests: write # Required for posting comments
jobs:
test:
runs-on: ubuntu-latest
steps:
...
- name: Run tests
run: |
pytest . --junitxml=junit/test-results.xml
- name: Publish pytest report
uses: sambyeol/publish-pytest-action@v2
if: ${{ always() }} # Even if the tests fail, publish the report
with:
junit-xml: junit/test-results.xmlThe action can be configured with the following options:
| Option | Default | Description |
|---|---|---|
junit-xml |
required | The path to the JUnit XML file. This can be generated by running pytest with the --junitxml option. |
coverage-xml |
null | The path to the coverage XML file. This can be generated by running pytest with the --cov=<your-module> --cov-report xml options. These options require the pytest-cov package. |
title |
Pytest Report |
The title of the comment. |
comment-mode |
new |
Controls how previous comments posted by this action are handled. - new: (Default) Always posts a new comment. - update: Updates the most recent comment with the same comment-identifier. Deletes older comments with the same identifier. If no comment-identifier is provided, a new comment with a warning is created. - hide: Minimizes all previous comments with the same comment-identifier and posts a new one. If no comment-identifier is provided, a new comment with a warning is created. - delete: Deletes all previous comments with the same comment-identifier and posts a new one. If no comment-identifier is provided, a new comment with a warning is created. Note: For update, hide, and delete modes to effectively manage comments, a comment-identifier is strongly recommended. |
comment-identifier |
'' (empty string) |
A unique string to identify the action's comment. If comment-mode is set to update, hide, or delete, this identifier is used to ensure that only the comment from the same job or matrix configuration (e.g., specific Python version and OS) is modified. Typically, you would construct this from matrix variables like py\${{ matrix.python-version }}-\${{ matrix.os }}. |