Published on

Enhance Your Workflows with pytest-action: A GitHub Action for pytest

Authors

We're introducing pytest-action, a GitHub Action that enables you to run pytest and output GitHub Job Summaries. This action integrates pytest-md and pytest-emoji, enhancing your test reports.

Instead of having to scroll through the logs of your CI Workflow to identify your failing test cases, pytest-action can generate a human-readable Job Summary:

Example Job Summary

Using pytest-action

To use pytest-action, you need to have Python and pytest installed in your pipeline. If job-summary is set to true, you also need to install pytest-md. If emoji is set to true, you need to install pytest-emoji.

Here's an example of how to use pytest-action in your workflow:

- name: Run pytest
  uses: quantco/pytest-action@v2
  with:
    verbose: true
    emoji: true
    job-summary: true
    custom-arguments: '-q'
    click-to-expand: true
    report-title: 'Test Report'

Generating Job Summaries

As highlighted in a recent GitHub blog post, GitHub Actions now support Job Summaries, allowing for custom Markdown content on the run summary generated by each job.

pytest-action leverages this feature to provide a rich and informative summary of your test runs. With the power of GitHub Flavored Markdown, you can create amazing workflows and enhance your experience with pytest-action.

Features

pytest-action provides several inputs for customization:

  • job-summary: Print a GitHub job summary.
  • verbose: Verbose output.
  • emoji: Use emojis in the output.
  • custom-arguments: Custom arguments to pass to pytest.
  • custom-pytest: Custom command to replace the pytest call. Can be a custom executable or something like poetry run pytest or micromamba run -n myenv pytest.
  • report-title: Title of the report.
  • click-to-expand: Add 'Click to expand' to the report.

Additional Settings

You can set the time zone of the job summary using the szenius/set-timezone action. If you want to use a conda environment, make sure to add it into your .bash_profile so that the conda environment automatically gets activated. mamba-org/setup-micromamba does this automatically for you.

Conclusion

pytest-action simplifies the process of running pytest and outputting GitHub Job Summaries. By integrating pytest-md and pytest-emoji, it enhances your test reports.

Feel free to check out the pytest-action GitHub repository and let us know what you think!