[](https://github.com/nteract/testbook/actions)
[](https://codecov.io/github/nteract/testbook?branch=master)
[](https://testbook.readthedocs.io/en/latest/?badge=latest)
[](https://pypi.org/project/testbook/)
[](https://www.python.org/downloads/release/python-360/)
[](https://www.python.org/downloads/release/python-370/)
[](https://www.python.org/downloads/release/python-380/)
[](https://github.com/ambv/black)
# 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:
```python
def func(a, b):
return a + b
```
You would write a unit test using `testbook` in a Python file as follows:
```python
import testbook
@testbook.testbook('/path/to/notebook.ipynb', execute=True)
def test_func(tb):
func = tb.ref("func")
assert func(1, 2) == 3
```
## Installing `testbook`
```{code-block} bash
pip install testbook
```
## Documentation
See [readthedocs](https://testbook.readthedocs.io/en/latest/) for more in-depth details.
## Development Guide
Read [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines on how to setup a local development environment and make code changes back to testbook.