Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing IPython Notebooks

I'm starting to use IPython notebooks to document some of my code with interactive usage examples. In order to avoid having the documentation get too far out of date from the code, I'd like the code in the notebook to get executed on a regular basis to catch any changes in output and to flag runtime errors.

I use nosetests to run regression tests and was wondering if there is a way to have it execute IPython Notebooks for this purpose. Note that I'm not trying to run nosetests from within the IPython notebook (as is done in ipython_nose). Something more along the lines of the doctest plugin. Does such a plugin exist?

like image 963
DMack Avatar asked Dec 09 '13 23:12

DMack


1 Answers

I don't know of an actual nose plugin to do it automatically, but here is a script showing the basic pieces that would be necessary for such a thing. Others have since forked it to add some functionality.

The gist is that you create the same Kernel object that the notebook uses, and run through the same execution that 'Run All' would do, and compare the resulting output. It has some primitive sanitization, which could probably largely be replaced by the right doctest functions, but it's not super complicated.

like image 115
minrk Avatar answered Nov 11 '22 00:11

minrk