[IPython-user] ipython not playing nicely with doctest?

Jeremy Dunck jdunck at gmail.com
Tue Jan 16 15:05:47 CST 2007


I have been stumped about a problem I was having with doctest, and
narrowed it down to an apparent bad interaction between doctest and
ipython.

Given a test.py with the following contents:
===========
"""
>>> def x():
...     return 1
...
>>> print x()
1

>>> x()
1

"""
==========

I would expect the tests to pass.  Indeed, under stock python 2.4, they do pass.

However, when using ipython (with cache_size=0), I get this:

===========
>>> import tests

>>> import doctest

>>> doctest.testmod(tests)
1
**********************************************************************
File "/home/jdunck/work/pegasus/tests.py", line 8, in tests
Failed example:
    x()
Expected:
    1
Got nothing
**********************************************************************
1 items had failures:
   1 of   3 in tests
***Test Failed*** 1 failures.
*** DocTestRunner.merge: 'tests' in both testers; summing outcomes.
(1, 3)
===========

Note that the failure is on line 8 -- the line that doesn't print the
result of x(); the line that -does- print the result passes.

Am I doing something foolish, or is this a limitation of using ipython
with doctest?

Thanks,
  Jeremy


More information about the IPython-user mailing list