Unidata/MetPy

View on GitHub
.github/actions/run-tests/action.yml

Summary

Maintainability
Test Coverage
name: 'Run Tests'
description: 'Run tests, and optionally doctests, uploading coverage and artifacts as necessary.'
inputs:
  run-doctests:
    description: 'Whether doctests should be run'
    required: true
    default: 'true'
  key:
    description: 'Key to use for coverage and artifacts'
    required: true
  upload-coverage:
    description: 'Whether to upload coverage report'
    required: false
    default: 'true'
runs:
  using: composite
  steps:
    - name: Set test data directory
      shell: bash
      run: echo "TEST_DATA_DIR=$GITHUB_WORKSPACE/staticdata" >> $GITHUB_ENV

    - name: Run tests
      id: run-tests
      # Need to use a login bash shell to get the conda env
      shell: bash -l {0}
      # By running coverage in "parallel" mode and "combining", we can clean up the path names
      run: |
        set -e -o pipefail
        python -m coverage run -p -m pytest --mpl -W error::metpy.deprecation.MetpyDeprecationWarning tests/ 2>&1 | tee tests-${{ inputs.key }}.log
        python -m coverage combine
        python -m coverage report
        python -m coverage xml

    - name: Run doctests
      if: ${{ inputs.run-doctests == 'true' }}
      shell: bash -l {0}
      env:
        PY_IGNORE_IMPORTMISMATCH: 1
      run: python -m pytest --doctest-modules -k "not test" src;

    - name: Upload test images
      if: failure()
      uses: actions/upload-artifact@v4
      with:
        name: ${{ inputs.key }}-images
        path: test_output/

    - name: Upload coverage artifact
      if: ${{ inputs.upload-coverage == 'true' }}
      uses: actions/upload-artifact@v4
      with:
        name: ${{ inputs.key }}
        path: coverage.xml
        retention-days: 7