--- aliases: - /2014/09/unit-tests-ipython-notebook categories: - python - jupyter date: 2014-09-30 14:00 layout: post slug: unit-tests-ipython-notebook title: Write unit tests as cells of IPython notebooks --- ## What? Plugin for `py.test` to write unit tests as cells in IPython notebooks: * Homepage on Github: * PyPi : * Install with `pip install pytest-ipynb` ## Why? Many unit testing fromeworks in Python, first of all the `unittest` package in the standard library, work very well for automating unit tests, but make it very difficult to debug interactively any failed test. [`py.test`](http://pytest.org) alleviates this problem by allowing to write just plain Python functions with `assert` statements (no boilerplate code), discover them automatically in any file that starts with `test` and write a useful report. I wrote a plugin for `py.test`, [`pytest-ipynb`](https://pypi.python.org/pypi/pytest-ipynb), that goes a step further and runs unit tests written as cells of any IPython notebook named `test*.ipynb`. The advantage is that it is easy to create and debug interactively any issue by opening the testing notebook interactively, then clean the notebook outputs and add it to the software repository. More details on Github: Suggestions welcome as comments or github issues. (Yes, works with Python 3)