Skip to content

Commit

Permalink
Use new setup
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH committed Sep 4, 2024
1 parent d99dafe commit 69dc8a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ jobs:
cache: 'pip'
- name: Install uv
run: pip install uv
- name: Install dependencies
run: uv pip install --system . pytest nbval jupyter nbconvert
- name: Install Mesa dependencies
run: uv pip install --system .
- name: Install tutorial dependencies
run: uv pip install --system pytest jupyter nbconvert seaborn pandas
# Run Pytest on Jupyter Notebooks
- name: Test Jupyter Notebooks with Pytest
run: pytest -rA -Werror -Wdefault::FutureWarning tests/test_tutorials.py
28 changes: 16 additions & 12 deletions tests/test_tutorials.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import glob

import nbformat
import pytest
from nbconvert.preprocessors import ExecutePreprocessor

# 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",
"--nbval-current-env", # Use the current environment
notebook,
]
)
@pytest.mark.parametrize("notebook_path", notebooks)
def test_notebook_execution(notebook_path):
# Load the notebook
with open(notebook_path) as f:
nb = nbformat.read(f, as_version=4)

# Set up the notebook execution
ep = ExecutePreprocessor(timeout=600, kernel_name="python3")

try:
# Execute the notebook and catch any errors
ep.preprocess(nb, {"metadata": {"path": "./"}})
except Exception as e:
pytest.fail(f"Notebook {notebook_path} failed: {e!s}")

0 comments on commit 69dc8a9

Please sign in to comment.