[TIP] pytest and ipynb

Pete Forman petef4+usenet at gmail.com
Tue Jun 21 15:30:55 PDT 2016

Hans Fangohr <fangohr.hans at gmail.com> writes:

> Pete, and all,
>> On 18 Jun 2016, at 08:29, Pete Forman <petef4+usenet at gmail.com> wrote:
>> Hans Fangohr <fangohr.hans at gmail.com> writes:
>>> Pete,
>>>> nbval provides a good way to test notebooks but my last questions
>>>> still stand. Is TDD fundamentally a bad fit for Jupyter or is just
>>>> that no-one has written a suitable implementation. If the latter
>>>> then I might step up to the mark.
>>> Ah, I had missed that you core question was how to (wether?) use TDD
>>> in Jupyter.
>>> I am certainly very interested in that question. I don’t think it is
>>> clear that TDD is generally a bad fit for Jupyter - I’d rather think
>>> nobody has explored this yet (or at least I haven’t heard about it),
>>> both from a workflow and a tools perspective.
>>> What is your anticipated model here? Write the tests in a normal
>>> python file, and develop in the notebook? Or have the tests in a
>>> different notebook? Or something else?
>> Either of your first two suggestions would work for me: test_foo.py
>> or test_foo.ipynb to test foo.ipynb. I've played a bit with
>> pytest-ipynb now and that does the latter. It can import Python
>> modules and unit test them.
>> What is needed is to import another notebook as the system under
>> test. I have seen a length way of doing that and presume that it will
>> either find its way into IPython or a package on PyPI.
>> Because pytest-ipynb is using cells to hold its tests decorator based
>> pytest features such as parameterize and xfail won't work.
> I have just sketched another way of doing this where notebooks are
> converted to python files, and we run ‘conventional’ testing of
> converted python code. A worked example is at
> https://github.com/fangohr/tdd-with-jupyter .
> If anybody is interested, we can extend this repo with more examples
> to gather different ways of doing TDD with jupyter.

That’s looking pretty cool. I’ve sent a pull request with a bit of

Pete Forman

More information about the testing-in-python mailing list