Notebooks rot fast
Jupyter notebooks are everywhere in ML repos — exploratory analysis, training scripts, demo flows, tutorial pages. They also rot the moment they're committed: outputs go stale, dependencies shift, the 'just works on my laptop' state ages out.
Treat notebooks like code. Test them in CI.
Tools
- papermill — execute a notebook end-to-end with parameterized inputs. Output is a new notebook with all cells run.
- pytest --nbmake — runs notebooks as pytest tests.
- jupyter nbconvert --execute — built-in, low-frills.
- nbqa — runs ruff / black / mypy on notebooks.
What to assert
- The notebook runs to completion without error.
- Specific cells produce the expected output (papermill + a small test script).
- Lint / format are clean (nbqa + ruff).
- Outputs are stripped before commit (use
nbstripoutor a pre-commit hook) so diffs stay readable.