Jupyter Notebook tests allow you to test code and output from Jupyter Notebook cells. This comprises of two parts:
Setting up the Jupyter Notebook.
Creating a custom test for Jupyter Notebooks. This test must be used in conjunction with other tests.
The steps are described in detail below.
First, in the Jupyter Notebook, edit the metadata for the cell you'd like to test. You can get to this by clicking View > Cell Toolbar > Edit Metadata.
You will need to add a unique identifier to the cell's metadata, for example, by generating a GUID using this site. You should add this value to the
eid keyword, as shown below:
Next, add the
autosave magic command to the top cell of the notebook, as follows:
This step is necessary because notebooks must be saved before the test can be run. Once this is completed, hide the cells' metadata, save the Jupyter Notebook, and save the lesson files.
Create a custom task with the following specifications:
When this custom test is run, it will save the cell contents and output as
.enb_<guid>.<extension> (see next section for more details).
For example, if the unique identifier you added to the cell's metadata is
d5137d, and you would like to use a code pattern test on the code within the cell, you would direct the code pattern test to search within
You will need one custom test per Jupyter Notebook you'd like to test and it should be enabled before any other tests, like so:
The following explains what files are created by the Jupyter Notebook Custom Tests and use cases for each:
Cell input will be saved as
.py files. These can then be checked using unit tests and code patterns.
Cell output will be saved as
.stdout files, depending on whether a
Errors are saved as
.er files. This is useful for testing whether an error was raised correctly.
Images created will be saved to
.png files, which can be used with image tests. Any text associated with the images will be saved as
.src files. You can these with code patterns.
If you are unsure of whether or not a user will use a
If you get stuck, don't hesitate to reach out for help!