[TIP] pytest and ipynb

Pete Forman petef4+usenet at gmail.com
Sat Jun 18 00:29:10 PDT 2016


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.

-- 
Pete Forman
https://payg-petef.rhcloud.com
(formerly on http://petef.22web.org/payg.html)




More information about the testing-in-python mailing list