Upgrade to Pro — share decks privately, control downloads, hide ads and more …

testbook - Unit test your Jupyter Notebooks

testbook - Unit test your Jupyter Notebooks

With widespread use of Jupyter Notebooks, it becomes important to write maintainable and reliable notebooks. testbook helps you unit test your notebooks in the conventional unit testing style, with the tests existing as a separate entity.

Rohit Sanjay

July 07, 2020
Tweet

More Decks by Rohit Sanjay

Other Decks in Programming

Transcript

  1. About me My name is Rohit Sanjay - Final year

    electronics engineering student - Google Summer of Code 2020 student working on testbook under the mentorship of Matthew Seal (@codeseal) - Love Python and C github.com/rohitsanj @imrohitsanj rohitsanjay.com
  2. Jupyter Notebooks - going beyond experimentation Jupyter Notebooks are no

    more just a tool for experimentation, but are often being using in production environments.
  3. Jupyter Notebooks can get very messy Code written to conduct

    data science experiments in Jupyter Notebooks can get messy. Enforcing good coding habits in Jupyter Notebooks can lead to maintainable and easily refactorable code. Some good habits are.. • Use functions to abstract away complexity • Smuggle code out of Jupyter notebooks as soon as possible • Apply test driven development • Make small and frequent commits Source: https://www.thoughtworks.com/insights/blog/coding-habits-data-scientists
  4. Test driven development for Jupyter Notebooks? Couple of approaches: •

    Write the tests in the notebook itself • Refactor code out of the notebooks and write them in separate Python modules that can then be independently unit tested.
  5. This is where testbook comes in You can write unit

    tests directly for Jupyter Notebooks, without refactoring code out of it into separate Python modules. Testbook can now help you write maintainable and reliable Jupyter Notebooks.
  6. Features • Write conventional unit tests for Jupyter Notebooks •

    Execute all or some specific cells before unit test • Share kernel context across multiple tests (using pytest fixtures) • Inject code into Jupyter notebooks • Works with any unit testing library - pytest, unittest or nose