Skip to content

Commit

Permalink
Add "tutorial" job in "pytest" CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Dec 11, 2023
1 parent 4775584 commit 045fffc
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 6 deletions.
86 changes: 85 additions & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
# Work around iiasa/ixmp#411
run: |
pytest message_ix \
-m "not nightly" \
-m "not nightly and not tutorial" \
-rA --verbose --color=yes --durations=20 \
--cov-report=xml \
--numprocesses=auto --dist=loadgroup || ( [ $? -eq 127 -a "${{ runner.os }}" = "Windows" ] && echo "Spurious exit code 127 from pytest" && exit 0)
Expand All @@ -125,6 +125,90 @@ jobs:
- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v3

tutorials:
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest

fail-fast: false

runs-on: ${{ matrix.os }}
name: Tutorials ${{ matrix.os }}

steps:
- name: Check out message_ix
uses: actions/checkout@v3
with:
fetch-depth: ${{ env.depth }}

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: "**/pyproject.toml"

- name: Set RETICULATE_PYTHON
# Use the environment variable set by the setup-python action, above.
run: echo "RETICULATE_PYTHON=$pythonLocation" >> $GITHUB_ENV
shell: bash

- uses: ts-graphviz/[email protected]
with:
macos-skip-brew-update: true

- uses: r-lib/actions/setup-r@v2
id: setup-r

- name: Cache GAMS installer, Python packages, and R packages
uses: actions/cache@v3
with:
path: |
gams
${{ env.R_LIBS_USER }}
key: ${{ matrix.os }}-gams${{ env.GAMS_VERSION }}-R${{ steps.setup-r.outputs.installed-r-version }}
restore-keys: |
${{ matrix.os }}-gams${{ env.GAMS_VERSION }}-
${{ matrix.os }}-
- uses: iiasa/actions/setup-gams@main
with:
version: ${{ env.GAMS_VERSION }}
license: ${{ secrets.GAMS_LICENSE }}

- name: Install Python package and dependencies
# By default, the below installs ixmp from the main branch. To run against
# other code, e.g. other branches for open PRs), temporarily edit as
# appropriate. DO NOT merge such changes to `main`.
run: |
pip install --upgrade "ixmp @ git+https://github.com/iiasa/ixmp.git@main"
pip install .[tests]
- name: Install R dependencies and tutorial requirements
run: |
install.packages("remotes")
remotes::install_cran(
c("dplyr", "IRkernel", "reticulate"),
dependencies = TRUE,
# force = TRUE,
)
IRkernel::installspec()
shell: Rscript {0}

- name: Run test suite using pytest
run: |
pytest message_ix \
-m "tutorial" \
-rA --verbose --color=yes --durations=20 \
--cov-report=xml \
--numprocesses=auto --dist=loadgroup
shell: bash

- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v3

pre-commit:
name: Code quality

Expand Down
13 changes: 8 additions & 5 deletions message_ix/tests/test_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
]

# Affects all tests in the file
pytestmark = pytest.mark.flaky(
reruns=5,
rerun_delay=2,
condition=GHA,
reason="Flaky; fails occasionally on GitHub Actions runners",
pytestmark = (
pytest.mark.tutorial,
pytest.mark.flaky(
reruns=5,
rerun_delay=2,
condition=GHA,
reason="Flaky; fails occasionally on GitHub Actions runners",
),
)


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ addopts = """
markers = [
"nightly: Slow-running nightly tests of particular scenarios.",
"rmessageix: test of the message_ix R interface.",
"tutorial: Tests of the tutorial Jupyter notebooks",
]

[tool.ruff]
Expand Down

0 comments on commit 045fffc

Please sign in to comment.