12.6 Including Unit Test Cases in a Notebook
It’s difficult to be sure that any software is trustworthy without a test suite. It can be awkward to unit test code in a Jupyter Notebook. One of the primary reasons testing is difficult is that a notebook is often used to ingest a very large volume of data. This means that computations in individual cells can take a very long time to complete. For a sophisticated machine learning model, this kind of time-consuming processing is typical.
One approach to creating test cases is to create a ”template” notebook used for unit testing. The template can be cloned and a source Path value changed to read the large data that is of real interest.
Since notebook .ipynb files are in the JSON format, it’s relatively easy to write a program to confirm that the cells of a notebook used to produce the desired results are (nearly) identical to the template notebook used for testing. Cells with specific...