Running pytest test functions inside a jupyter notebook

I created ipython_pytest for this purpose and used it in my PyCon Helsinki 2016 presentation.

You would use the tool like this:

%%pytest

def test_my_stuff():
    assert 42 == 42

Unfortunately I couldn't find a way to make functions and classes defined in the notebook available to test functions in the test cell. I'd appreciate if someone comes up with a solution for that.


There is a similar module that looks very mature: https://github.com/chmp/ipytest

It is referenced in the module developed by @akaiola and is more active and regularly updated / maintained.

Here is an example from the Github repository (https://github.com/chmp/ipytest/blob/master/Example.ipynb)

Jupyter Notebook with iPytest

And another one I have created recently

example 2