Forged from runtests (Matt Davis) gist: https://gist.github.com/jiffyclub/4013594
In [1]:
%load_ext ipynbtester
While loading extension, IPython notebook informs that module is not part of the core distribution, but third party module instead.
Tests must be defined as function starting with test -keyword. Underscore is not necessary after the keyword, but good for readability. Below three different tests are defined, first indicating successful test assertion, second having failure on assertion and third having error during script execution.
In [2]:
def test_my_test_ok():
assert True == True
def test_my_test_fail():
assert True == False
def test_my_test_error():
assert True == none
In [3]:
%runaway
Out[3]:
Styles below are just for nice look for result table, not necessary for ipynbtester functionality itself.
In [4]:
from IPython.core.display import HTML
with open('styles.css') as f:
css = f.read()
HTML('<style>%s</style>' % css)
Out[4]:
Copyright (c) 2014 Marko Manninen