Skip to content

Tests

Tests #3027

Workflow file for this run

name: Tests
on:
# Uncomment this entry only to debug the workflow
# pull_request:
# branches: [ main ]
pull_request_target:
branches: [ main ]
types: [ labeled, opened, reopened, synchronize ]
# 05:00 UTC = 06:00 CET = 07:00 CEST
schedule:
- cron: "0 5 * * *"
# Cancel previous runs that have not completed
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
defaults:
run:
shell: bash
env:
GAMS_VERSION: 48.6.1 # Oldest version of GAMS that can reliably be downloaded
depth: 100 # Must be large enough to include the most recent release
label: "safe to test" # Label that must be applied to run on PRs from forks
python-version: "3.14" # For non-matrixed jobs
# Install:
# - dask: to work around https://github.com/khaeru/genno/issues/171
# - ixmp: from its `main` branch.
# - all other dependencies from PyPI.
#
# To test against other code, such as other branches for open PRs, temporarily
# add lines as appropriate. These lines SHOULD NOT be merged to `main`.
upstream-versions: |
"dask < 2025.4.0" \
"ixmp @ git+https://github.com/iiasa/ixmp.git@main" \
jobs:
check:
name: check permissions
runs-on: ubuntu-latest
steps:
- if: >
!(
github.event_name == 'schedule'
|| github.repository == github.event.pull_request.head.repo.full_name
|| contains(github.event.pull_request.labels.*.name, env.label)
)
run: |
echo "Pytest workflow will not run for branch in fork without label \`${{ env.label }}\`." >>$GITHUB_STEP_SUMMARY
exit 1
pytest:
needs: [ check ]
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
python-version:
- "3.10" # Earliest version supported by message_ix
- "3.11"
- "3.12"
- "3.13"
- "3.14" # Latest version supported by message_ix
# Below this comment are newly released or development versions of
# Python. For these versions, binary wheels are not available for some
# dependencies, e.g. llvmlite, numba, numpy, and/or pandas. Compiling
# these on the job runner requires a more elaborate build environment,
# currently out of scope for the message_ix project.
# - "3.15.0-alpha.1" # Development version
fail-fast: false
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }}-py${{ matrix.python-version }}
steps:
- name: Check out message_ix
uses: actions/checkout@v5
with:
fetch-depth: ${{ env.depth }}
ref: ${{ github.event_name != 'pull_request_target' && github.ref || github.event.pull_request.head.sha }}
- name: Fetch tags (for setuptools-scm)
run: git fetch --tags --depth=${{ env.depth }}
- name: Set up uv, Python
uses: astral-sh/setup-uv@v7
with:
activate-environment: true
enable-cache: true
python-version: ${{ matrix.python-version }}
- uses: ts-graphviz/setup-graphviz@v2
# Work around ts-graphviz/setup-graphviz#630
if: matrix.os != 'macos-13'
- name: Set Java version on Windows
if: startsWith(matrix.os, 'windows-')
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '21'
- name: Cache GAMS installer
uses: actions/cache@v4
with:
path: |
gams
key: ${{ matrix.os }}-gams${{ env.GAMS_VERSION }}
restore-keys: |
${{ matrix.os }}-
- uses: iiasa/actions/setup-gams@main
with:
version: ${{ env.GAMS_VERSION }}
license: ${{ secrets.GAMS_LICENSE }}
- name: Install the package and dependencies
run: uv pip install --upgrade ${{ env.upstream-versions }} .[tests]
- name: Run test suite using pytest
env:
# For test_cli.test_dl; see code in message_ix.cli.dl
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pytest message_ix \
-m "not nightly and not tutorial" \
--color=yes --durations=20 -rA --verbose \
--cov-report=xml \
--numprocesses=auto --dist=loadgroup
- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
tutorials:
needs: [ check ]
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
fail-fast: false
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} tutorials
steps:
- name: Check out message_ix
uses: actions/checkout@v5
with:
fetch-depth: ${{ env.depth }}
ref: ${{ github.event_name != 'pull_request_target' && github.ref || github.event.pull_request.head.sha }}
- name: Set up uv, Python
uses: astral-sh/setup-uv@v7
with:
activate-environment: true
enable-cache: true
python-version: ${{ env.python-version }}
- name: Set Java version on Windows
if: startsWith(matrix.os, 'windows-')
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '21'
- name: Set RETICULATE_PYTHON
# Retrieve the Python executable set up above
run: echo "RETICULATE_PYTHON=$(uv python find)" >> "$GITHUB_ENV"
- uses: r-lib/actions/setup-r@v2
id: setup-r
with:
windows-path-include-rtools: false
- name: Cache GAMS installer and R packages
uses: actions/cache@v4
with:
path: |
gams
${{ env.R_LIBS_USER }}
key: tutorial-${{ matrix.os }}-gams${{ env.GAMS_VERSION }}-R${{ steps.setup-r.outputs.installed-r-version }}
restore-keys: |
tutorial-${{ matrix.os }}-gams${{ env.GAMS_VERSION }}-
tutorial-${{ matrix.os }}-
- uses: iiasa/actions/setup-gams@main
with:
version: ${{ env.GAMS_VERSION }}
license: ${{ secrets.GAMS_LICENSE }}
- name: Install the package and dependencies
run: uv pip install --upgrade ${{ env.upstream-versions }} .[tests]
- name: Install R dependencies and tutorial requirements
run: |
install.packages(c("dplyr", "IRkernel", "reticulate"))
IRkernel::installspec()
shell: Rscript {0}
- name: Run test suite using pytest
run: |
pytest message_ix \
-m "tutorial" \
--color=yes --durations=20 -rA --verbose \
--cov-report=xml \
--numprocesses=auto --dist=loadgroup
- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
pre-commit:
name: Code quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event_name != 'pull_request_target' && github.ref || github.event.pull_request.head.sha }}
- uses: astral-sh/setup-uv@v7
with: { enable-cache: true, python-version: "${{ env.python-version }}" }
- name: Clear and re-create the pre-commit environments
run: uvx pre-commit clean
if: github.event_name == 'schedule' # Comment this line to force clear
- run: |
uvx --with=pre-commit-uv \
pre-commit run \
--all-files --color=always --show-diff-on-failure --verbose