nbmake is a pytest plugin designed for testing Jupyter notebooks. It executes notebooks programmatically, allowing for continuous integration and automated quality checks on documentation and research materials. Currently at version 1.5.5, the library maintains an active development cadence, frequently releasing updates to support new Python and Pytest versions and address user feedback.
pip install nbmake pytestVerified import paths — ran on the pinned version, not inferred.
To quickly test a Jupyter notebook, install `nbmake` and `pytest`, then invoke pytest with the `--nbmake` flag on your notebook file(s). nbmake will execute the notebook from top to bottom, failing if any cell raises an unhandled exception or an assertion fails. Wildcards can be used to test multiple notebooks.
Upgrade to Python 3.8+ (preferably 3.9+) or pin nbmake to a version <1.5.0.
Upgrade to Python 3.9 or newer. Python 3.12 is officially supported by nbmake 1.5.5.
Ensure all necessary Python packages are installed in the test environment (e.g., via `pip install -e .` for local packages or `pip install -r requirements.txt`). For kernel issues, install the required Jupyter kernel (`python -m ipykernel install --user --name mycustomkernel`) or use `--nbmake-kernel=mycustomkernel` to override. Use `--nbmake-find-import-errors` to specifically diagnose import issues.
Increase the per-cell timeout using `pytest --nbmake --nbmake-timeout=<seconds>` (e.g., `--nbmake-timeout=3000` for 50 minutes). Alternatively, mock out variables or skip complex cells using notebook metadata.
For a cell expected to raise an exception, add `"tags": ["raises-exception"]` to its metadata. For an entire notebook, add `"execution": {"allow_errors": true}` to its top-level metadata. To skip a cell entirely, use `"tags": ["skip-execution"]`.Install your project in editable mode (`pip install -e .`) so Python can find modules. Alternatively, ensure the notebook's directory is on the Python path during testing, or modify `sys.path` within the notebook itself, though this is generally less robust.