Run Notebook Tests
During development or research, you may need to validate your notebook tests. This topic describes how to author, run, and debug notebook tests to ensure that they run as expected.
Limitations
Before running notebook tests, note the following limitations for running notebook tests:
- Notebook tests can be executed only from k8s based clusters.
- The notebook's kernel must correspond to a seeded
ImplLanguage.Runtime.
Seeding notebook tests for CI
To test notebooks in CI, the following setup is necessary:
The notebook file should be stored in either package resources or in external storage for the package (for example,
s3). Usually,.../<pkg>/resources/**/*.ipynbis a good place.<pkg>denotes your test's package name/**/implies you can have any sub-path directory structure
If the notebook is used only for testing you can put it under test resources: .../<pkg>/test/resources/**/*.ipynb.
Seed a
JupyterNotebookjson for this notebook. The seeded file can go in either.../<pkg>/seed/JupyterNotebook/*.jsonor to.../<pkg>/test/seed/JupyterNotebook/*.json.If you have a dependent file that is needed for a notebook test to run (for example, a csv or txt file), seed a corresponding
JupyterFilejson for the dependent file. The seeded file can go in either.../<pkg>/seed/JupyterFile/*.jsonor to.../<pkg>/test/seed/JupyterFile/*.json. After seeding theJupyterFilejson, you need to add theJupyterFileto theJupyterNotebookjson as a dependency. To do this, add thetype, id, name, pathof seeded JupyterFile to thenotebookDependenciesarray in the seeded JupyterNotebook's json.Create test file in
.../<pkg>/test/notebook/**/test_*.json. This file corresponds toJupyterNotebook.TestSpec, and contains the path to the notebook as defined in seededJupyterNotebook(notexternalFilebutpath).Example of file:
JSON{ "path": "home/notebooks/simple-notebook.ipynb" }Where
home/notebooks/simple-notebook.ipynbis a path to thesimple-notebook.ipynbin the JupyterLab file browser. This path can be copied from JupyterLab UI by right-clicking at the notebook name in Jupyter file browser and selectingCopy Path.JupyterNotebook.TestSpechas other options liketimeoutSecondsorconnectionTimeoutSecondsfor controlling notebook testing and can be set like in the following example:JSON{ "path": "home/notebooks/simple-notebook.ipynb", "timeoutSeconds": 180, "connectionTimeoutSeconds": "180" }This example reduces notebook execution timeout and connection timeout to 3 minutes. See defaults values and other parameters in documentation for Type
JupyterNotebook.TestSpec.