[IPython-user] run doctests interactively more easily

Fernando Perez fperez.net@gmail....
Fri Dec 28 02:43:43 CST 2007

Hey folks,

[those on the numpy list, sorry for the dupe]

I just added this to ipython:


You can load it in your startup file or interactively via

from IPython.dtutils import idoctest

Type idoctest? for calling details.

This will enable you to do things like:

In [96]: idoctest
-------> idoctest()   # at this point, you start typing/pasting your
doctest.  Hit Ctrl-D or two blanks to end:

    >>> for i in range(10):
    ...     print i,
    0 1 2 3 4 5 6 7 8 9

1 items passed all tests:
   1 tests in interactive doctest
1 tests in 1 items.
1 passed and 0 failed.
Test passed.

If you have a failing doctest that you'd like to debug, you can use
'eraise=True' and errors will be immediately raised, so you can then
call %debug to debug them.

This should come in handy for all those doctests that you're all going
to write tomorrow.  If you aren't running off SVN ipython, you can
simply copy the above file somewhere and load it interactively once
ipython is running, it doesn't depend on any other changes to ipython.

It probably still needs a bit of work to make it more convenient, so
I'm open to feedback.  But it should make life easier when writing
frequent doctests.



More information about the IPython-user mailing list