Package: treon
treonEasy to use test framework for Jupyter Notebooks.Runs notebook top to bottom and flags execution errors if anyRunsunittestpresent in your notebook code cellsRunsdoctestpresent in your notebook code cellsWhy should you use it?Start testing notebooks without writing a single line of test codeMultithreaded execution for quickly testing a set of notebooksExecutes every Notebook in a fresh kernel to avoid hidden state problemsPrimarily a command line tool that can be used easily in any Continuous Integration (CI) systemInstallationpip install treonUsageTreon will execute notebook from top to bottom and the test fails if any code cell returns an error. Additionally, one can write unittest & doctest to test specific behaviour (examples shown below).$ treon
Executing treon version 0.1.4
Recursively scanning /workspace/treon/tmp/docs/site/ru/guide for Notebooks...

-----------------------------------------------------------------------
Collected following Notebooks for testing
-----------------------------------------------------------------------
/workspace/treon/tmp/docs/site/ru/guide/keras.ipynb
/workspace/treon/tmp/docs/site/ru/guide/eager.ipynb
-----------------------------------------------------------------------

Triggered test for /workspace/treon/tmp/docs/site/ru/guide/keras.ipynb
Triggered test for /workspace/treon/tmp/docs/site/ru/guide/eager.ipynb

test_sum (__main__.TestNotebook) ...
ok
test_sum (__main__.TestNotebook2) ...
ok
test_sum (__main__.TestNotebook3) ...
ok

----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK

-----------------------------------------------------------------------
TEST RESULT
-----------------------------------------------------------------------
/workspace/treon/tmp/docs/site/ru/guide/keras.ipynb       -- PASSED
/workspace/treon/tmp/docs/site/ru/guide/eager.ipynb       -- PASSED
-----------------------------------------------------------------------
2 succeeded, 0 failed, out of 2 notebooks tested.
-----------------------------------------------------------------------Command line argumentsUsage:
  treon
  treon [PATH] [--threads=<number>] [-v] [--exclude=<string>]...

Arguments:
  PATH                File or directory path to find notebooks to test. Searches recursively for directory paths. [default: current working directory]

Options:
  --threads=<number>  Number of parallel threads. Each thread processes one notebook file at a time. [default: 10]
  -e=<string> --exclude=<string>  Option for excluding files or entire directories from testing. All files whose
                      absolute path starts with the specified string are excluded from testing. This option can be
                      specified more than once to exclude multiple files or directories. If the exclude path is
                      a valid directory name, only this directory is excluded.
  -v --verbose        Print detailed output for debugging.
  -h --help           Show this screen.
  --version           Show version.unittest exampleYou just need to add tests as shown below & treon would execute them and report the result on the console. Seethisfor more details on how to write unittest.doctest exampleYou just need to add tests as shown below & treon would execute them and report the result on the console. Seethisfor more details on how to write doctest.Note about dependenciesYou need to run treon from environment (virtualenv/pipenv etc.) that has all the dependencies required for Notebooks under testtreon only works with python3+ environments and uses python3 kernel for executing notebooksDevelopmentFor development, you may use below to create a Python interpreter that resides invenvin the current working directory, and to install all of treon's dependencies:$ virtualenv venv
$ source venv/bin/activate
$ pip install -e .
$ pip install -r requirements-dev.txt
$ treon --help # should workBecause the script installs the package as editable, you can make changes in the source tree and use thetreoncommand to immediately validate them. If this does not appear to work, check that you are using a the proper virtual environment, and that the package is indeed installed in editable mode:$ which treon # should point into your virtualenv
/path/to/my/venv/bin/treon
$ pip list --local | grep treon # should point to the source tree
treon                0.1.4                /workspace/treonPlease refer to theMakefilefor supplementary development tasks.
In particular, the following targets may be relevant when validating changes before committing:$ make lint # check treon's source for code style errors
$ make test # run all testsMotivationOur aim atReviewNBis to make notebooks a first class entity in the production workflow. We've built a code review system for Notebooks. The next step is tobuild a CI pipeline& treon is the core tool in that effort. It is licensed liberally (MIT) & I foresee it being used as an independent tool as well. You can use it locally and/or integrate with CI system of your choice.For motivation, checkoutNetflix's blogto see how notebooks are graduating from scratchpad to a part of production workflow.ContributeIf you see any problem, open an issue or send a pull request. You can write toteam@reviewnb.comfor any questions.