Skip to content

:octocat: GitHub Action to run pytest with GitHub Job Summaries support 🐍 🚀

Notifications You must be signed in to change notification settings

Quantco/pytest-action

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Action for pytest

This GitHub Action allows you to run pytest and output GitHub Job Summaries. For creating the job summaries, this action uses pytest-md and pytest-emoji.

- 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'

You need to have Python as well as pytest installed in your pipeline before you can run this action. 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.

When job-summary is set to true, the action will output a Job Summary.

Example Job Summary Example Job Summary

Inputs

parameter description required default
job-summary Print a GitHub job summary false true
verbose Verbose output false true
emoji Use emojis in the output false true
custom-arguments Custom arguments to pass to pytest false
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. false pytest
report-title Title of the report false Test Report
click-to-expand Add 'Click to expand' to the report false true

Setting time zone

If you want to change the time zone of the job summary, you may want to use the szenius/set-timezone action:

- name: Set timezone
  uses: szenius/set-timezone@ce9c440bc3af4f51b28d7ef7e5c47ee8f26c8dcb
  with:
    timezone: 'Europe/Berlin'

Activating conda environments

This action uses bash -l {0} as the shell to run pytest in, i.e., the login shell that also sources your .bash_profile. When using bash in GitHub Actions, it doesn't source your .bash_profile by default. If you want to use a conda environment, you need to make sure to add it into your .bash_profile s.t. the conda environment automatically gets activated. mamba-org/setup-micromamba does this automatically for you.

- uses: mamba-org/setup-micromamba@v1
  with:
    environment-name: myenv
    create-args: >-
      python=3.11
      pytest
      numpy
      pytest-md
      pytest-emoji
# first checkout and then use the action because dependabot crashes when it sees private repositories
- name: Checkout quantco/pytest-action
  uses: actions/checkout@v3
  with:
    repository: quantco/pytest-action
    ref: v2
    token: ${{ secrets.FQ_GH_TOKEN }}
    path: .github/pytest-action
- name: Run unittests
  uses: ./.github/pytest-action

Example Usage

name: Run Python tests

on: [push]

jobs:
  build:
    name: Run tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.6", "3.7", "3.8", "3.9"]

    steps:
      - uses: szenius/set-timezone@ce9c440bc3af4f51b28d7ef7e5c47ee8f26c8dcb
        with:
          timezoneLinux: "Europe/Berlin"
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: pip install pytest pytest-md pytest-emoji
      # first checkout and then use the action because dependabot crashes when it sees private repositories
      - name: Checkout quantco/pytest-action
        uses: actions/checkout@v3
        with:
          repository: quantco/pytest-action
          ref: v2
          token: ${{ secrets.FQ_GH_TOKEN }}
          path: .github/pytest-action
      - name: Run unittests
        uses: ./.github/pytest-action
        with:
          emoji: false
          verbose: false
          job-summary: true

About

:octocat: GitHub Action to run pytest with GitHub Job Summaries support 🐍 🚀

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages