Python Tests for Jupyter Notebooks

Part 1: Jupyter Notebooks Needs Tests

Part 2: What is nbval?

Part 3: How to Use nbval?

$ py.test --nbval -v 03-data-types-structures.ipynb============================= test session starts =========platform darwin -- Python 3.8.0, pytest-5.3.1, ...plugins: nbval-0.9.3collected 137 items03-data-types-structures::ipynb::Cell 0 PASSED       [  0%]03-data-types-structures::ipynb::Cell 1 PASSED       [  1%]03-data-types-structures::ipynb::Cell 2 PASSED       [  2%]...03-data-types-structures::ipynb::Cell 136 PASSED     [100%]===================== 137 passed in 6.08s =================

Part 4: Summary

Parts 5: Codes Demonstration

import numpy as np
print('This is not going to be tested')
print(np.random.randint(1, 20000))
print("This will be tested even in case of relaxed testing")
print(6 * 7)
print("Entering infinite loop...")
while True:
print("This exception will be tested")
raise RuntimeError("Foo")





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Programmatically create Kafka topics using Spring Kafka

Database Normalization

Integrating Selenium with Behat and Mink

Kubernetes for validating

Understanding OOPs w/ Pokémon — 01

Fit of univariate distributions to non-censored data [under review]

Why GitHub Sponsors is bigger than we think

CS373 Fall 2020: Jonathon Lowe (Third Entry)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Parsing XML into pandas DataFrames

Data Types In Python

Python SQLite

Python — Functions