Skip to content

Commit

Permalink
CI: Add script and job to test tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH committed Sep 4, 2024
1 parent 0a3ae22 commit 25cdf5f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@ jobs:
run: |
cd mesa-examples
pytest -rA -Werror -Wdefault::FutureWarning test_examples.py
tutorials:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pip'
- name: Install uv
run: pip install uv
- name: Install dependencies
run: uv pip install --system . pytest nbval jupyter nbconvert
# Run Pytest on Jupyter Notebooks
- name: Test Jupyter Notebooks with Pytest
run: pytest -rA -Werror -Wdefault::FutureWarning tests/test_tutorials.py
21 changes: 21 additions & 0 deletions tests/test_tutorials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import glob

import pytest

# Locate all notebooks in docs and subdirectories
notebooks = glob.glob("docs/**/*.ipynb", recursive=True)


# Parameterize the test with all found notebooks
@pytest.mark.parametrize("notebook", notebooks)
def test_notebook_execution(notebook):
# This runs each notebook using nbval and ensures there are no errors
pytest.main(
[
"--nbval",
"--current-env", # Use the current environment
"--sanitize-with",
".sanitize_config.yaml", # Optional: If you want to handle variable output, use this
notebook,
]
)

0 comments on commit 25cdf5f

Please sign in to comment.