Skip to content

Tests

Tests #21169

Workflow file for this run

# Test PyGMT on Linux/macOS/Windows
#
# This workflow runs regular PyGMT tests and uploads test coverage reports stored in
# `.coverage.xml` to https://app.codecov.io/gh/GenericMappingTools/pygmt via the
# [Codecov GitHub Action](https://github.com/codecov/codecov-action). More codecov
# related configurations are stored in `.github/codecov.yml`. If any tests fail, it also
# uploads the diff images as workflow artifacts.
#
# It is run:
# 1. on every commit to the main branch
# 2. on every commit to the pull request branches, unless the pull requests only contain
# non-code changes.
# 3. when a new release is published
#
# It is also scheduled to run daily on the main branch.
#
# In draft pull request, only jobs on Linux are triggered to save on Continuous
# Integration resources:
#
# - Minimum supported Python + core packages (minimum supported versions)
# + optional packages (minimum supported versions if any)
# - Latest Python + core packages (latest versions) + optional packages
# - Last release before the latest Python + core packages
#
name: Tests
on:
push:
branches: [ main ]
paths:
- 'pygmt/**'
- '.github/workflows/ci_tests.yaml'
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
paths:
- 'pygmt/**'
- '.github/workflows/ci_tests.yaml'
workflow_dispatch:
release:
types:
- published
# Schedule daily tests
schedule:
- cron: '0 0 * * *'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
test:
name: ${{ matrix.os }} - Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
environment:
name: pr-tests
deployment: false
permissions:
id-token: write # This is required for requesting OIDC token for codecov
strategy:
fail-fast: false
matrix:
python-version: ['3.12', '3.14']
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest]
# Is it a draft Pull Request (true or false)?
isDraft:
- ${{ github.event.pull_request.draft }}
# Only run jobs on Ubuntu for draft PRs
exclude:
- os: ubuntu-24.04-arm
isDraft: true
- os: macos-latest
isDraft: true
- os: windows-latest
isDraft: true
include:
# Python 3.12 + core packages (minimum supported versions) + optional packages (minimum supported versions if any)
- python-version: '3.12'
numpy-version: '2.1'
pandas-version: '=2.3'
xarray-version: '=2024.7'
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray netCDF4 sphinx-gallery'
# Python 3.14 + core packages (latest versions) + optional packages
- python-version: '3.14'
numpy-version: '2.5'
pandas-version: ''
xarray-version: ''
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray netCDF4 sphinx-gallery'
# Python 3.13 + core packages (Linux only)
- os: 'ubuntu-latest'
python-version: '3.13'
numpy-version: ''
pandas-version: ''
xarray-version: ''
optional-packages: ''
timeout-minutes: 30
defaults:
run:
shell: bash -l {0}
# Environment variables used by codecov
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
NUMPY: ${{ matrix.numpy-version }}
steps:
# Checkout current git repository
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# fetch all history so that setuptools-scm works
fetch-depth: 0
persist-credentials: false
lfs: true
- name: Get current week number of year
id: date
run: echo "date=$(date +%Y-W%W)" >> $GITHUB_OUTPUT # e.g., 2024-W19
# Install Micromamba with conda-forge dependencies
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@f457c30a868e4760d3a6fcea5f25dc655b8edf39 # v3.2.1
with:
environment-name: pygmt
cache-environment: true
# environment cache is persistent for one week.
cache-environment-key: micromamba-environment-${{ steps.date.outputs.date }}
create-args: >-
python=${{ matrix.python-version }}${{ matrix.optional-packages }}
gmt=6.7.0
ghostscript=10.07.1
numpy=${{ matrix.numpy-version }}
pandas${{ matrix.pandas-version }}
xarray${{ matrix.xarray-version }}
packaging
make
pip
python-build
pytest
pytest-cov
pytest-doctestplus
pytest-mpl
pytest-rerunfailures
# Download cached remote files (artifacts) from GitHub
- name: Download remote data from GitHub
uses: $/.github/actions/download-gmt-cache
# Install the package that we want to test
- name: Install the package
run: make install
# Run the regular tests
- name: Run tests
env:
GMT_DATA_SERVER: https://opentopography.s3.sdsc.edu/gmtdata
run: |
log_file="${RUNNER_TEMP}/pytest.log"
make test PYTEST_EXTRA="-r P --reruns 2" 2>&1 | tee "${log_file}"
exit_code=${PIPESTATUS[0]}
if [[ "${RUNNER_OS}" == "Windows" && "${exit_code}" -eq 2 ]] && grep -q "make: .* Error 2816" "${log_file}"; then
echo "Tests exited with make error 2816 (segmentation fault) on Windows; allowing workflow to continue."
exit 0
fi
exit "${exit_code}"
# Upload diff images on test failure
- name: Upload diff images if any test fails
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: failure()
with:
name: artifact-${{ matrix.os }}-${{ matrix.python-version }}
path: tmp-test-dir-with-unique-name
# Upload coverage to Codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
if: success() || failure()
with:
use_oidc: true
files: ./coverage.xml # optional
env_vars: OS,PYTHON,NUMPY
fail_ci_if_error: false