-
Notifications
You must be signed in to change notification settings - Fork 880
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |