[TIP] pytest and ipynb

Pete Forman petef4+usenet at gmail.com
Mon Jun 13 12:02:14 PDT 2016

In TDD I write test_foo.py so that I can verify foo.py for validity and
coverage. Recently I have been using Jupyter / IPython where the code
and docs are in an ipynb notebook.

What is the recommended way to run pytest on a test_foo.ipynb?

I've found a couple of solutions but to slightly different questions.

https://pypi.python.org/pypi/pytest-ipynb enables you to write tests in
an ipynb. That enables you to build tests into a notebook but does not
separate the tests from the product.

https://github.com/computationalmodelling/nbval is a regression testing
tool for Jupyter. It compares outputs with a previous run.

Am I asking the right question? What is best practice for testing ipynb?

Pete Forman

More information about the testing-in-python mailing list