Skip to content
bookmark

GitHub Action

pytest-results-actions

v0.6.0 Latest version

pytest-results-actions

bookmark

pytest-results-actions

Post pytest results to the workflow summary

Installation

Copy and paste the following snippet into your .yml file.

              

- name: pytest-results-actions

uses: pmeier/[email protected]

Learn more about this action in pmeier/pytest-results-action

Choose a version

pytest-results-action

BSD-3-Clause License Project Status: WIP

pytest-results-action is a Javascript action for GitHub Actions to surface failing pytest tests without crawling through logs.

Why do I need it?

For all the awesomeness GitHub Actions brings, compared to other CI providers, logs above a few thousands lines load painfully slow. This can happen quite fast in larger test suites and is almost a given if one runs pytest in verbose mode, i.e. with -v set.

In addition to loading faster, other CI providers have an option to surface failing tests so there is no need to look at the logs in most cases. For example, on CircleCI using the builtin step store_test_results is sufficient.

pytest-results-action aims to bring the same UX to GitHub Actions.

How do I use it?

To be able to surface failing tests, pytest-results-action parses a JUnit XML file generated by pytest. For this the --junit-xml option needs to be set. The same value needs to be passed to the path input of pytest-results-action.

Since failing tests mean a non-zero exit code of pytest, if: always() needs to be set for pytest-results-action to run regardless.

- name: Run tests
  run: pytest --junit-xml=test-results.xml

- name: Surface failing tests
  if: always()
  uses: pmeier/pytest-results-action@main
  with:
    # A list of JUnit XML files, directories containing the former, and wildcard
    # patterns to process.
    # See @actions/glob for supported patterns.
    path: test-results.xml

    # (Optional) Add a summary of the results at the top of the report
    summary: true

    # (Optional) Select which results should be included in the report.
    # Follows the same syntax as `pytest -r`
    display-options: fEX

    # (Optional) Fail the workflow if no JUnit XML was found.
    fail-on-empty: true

    # (Optional) Title of the test results section in the workflow summary
    title: Test results

The report will be posted to the workflow summary.