testbook0.4.2
Published
A unit testing framework for Jupyter Notebooks
pip install testbook
Package Downloads
Authors
Project URLs
Requires Python
>=3.6
Dependencies
- nbformat
(>=5.0.4)
- nbclient
(>=0.4.0)
- codecov
; extra == 'dev'
- coverage
; extra == 'dev'
- ipython
; extra == 'dev'
- ipykernel
; extra == 'dev'
- ipywidgets
; extra == 'dev'
- pandas
; extra == 'dev'
- pytest
(>=4.1) ; extra == 'dev'
- pytest-cov
(>=2.6.1) ; extra == 'dev'
- check-manifest
; extra == 'dev'
- flake8
; extra == 'dev'
- tox
; extra == 'dev'
- bumpversion
; extra == 'dev'
- xmltodict
; extra == 'dev'
- pip
(>=18.1) ; extra == 'dev'
- wheel
(>=0.31.0) ; extra == 'dev'
- setuptools
(>=38.6.0) ; extra == 'dev'
- twine
(>=1.11.0) ; extra == 'dev'
- black
; (python_version >= "3.6") and extra == 'dev'
- Sphinx
(<3.0,>=1.7) ; extra == 'sphinx'
- sphinx-book-theme
(==0.0.35) ; extra == 'sphinx'
- myst-parser
(==0.9.1) ; extra == 'sphinx'
- codecov
; extra == 'test'
- coverage
; extra == 'test'
- ipython
; extra == 'test'
- ipykernel
; extra == 'test'
- ipywidgets
; extra == 'test'
- pandas
; extra == 'test'
- pytest
(>=4.1) ; extra == 'test'
- pytest-cov
(>=2.6.1) ; extra == 'test'
- check-manifest
; extra == 'test'
- flake8
; extra == 'test'
- tox
; extra == 'test'
- bumpversion
; extra == 'test'
- xmltodict
; extra == 'test'
- pip
(>=18.1) ; extra == 'test'
- wheel
(>=0.31.0) ; extra == 'test'
- setuptools
(>=38.6.0) ; extra == 'test'
- twine
(>=1.11.0) ; extra == 'test'
- black
; (python_version >= "3.6") and extra == 'test'
testbook
testbook is a unit testing framework extension for testing code in Jupyter Notebooks.
Previous attempts at unit testing notebooks involved writing the tests in the notebook itself. However, testbook will allow for unit tests to be run against notebooks in separate test files, hence treating .ipynb files as .py files.
testbook helps you set up conventional unit tests for your Jupyter Notebooks.
Here is an example of a unit test written using testbook
Consider the following code cell in a Jupyter Notebook:
def func(a, b):
return a + b
You would write a unit test using testbook
in a Python file as follows:
from testbook import testbook
@testbook('/path/to/notebook.ipynb', execute=True)
def test_func(tb):
func = tb.get("func")
assert func(1, 2) == 3
Installing testbook
pip install testbook
NOTE: This does not install any kernels for running your notebooks. You'll need to install in the same way you do for running the notebooks normally. Usually this is done with pip install ipykernel
Alternatively if you want all the same dev dependencies and the ipython kernel you can install these dependencies with:
pip install testbook[dev]
Documentation
See readthedocs for more in-depth details.
Development Guide
Read CONTRIBUTING.md for guidelines on how to setup a local development environment and make code changes back to testbook.