[SciPy-dev] Using doctest

David M. Cooke cookedm at physics.mcmaster.ca
Sun Oct 30 17:13:59 CST 2005


On Oct 30, 2005, at 03:05, Arnd Baecker wrote:
> On Sat, 29 Oct 2005, David M. Cooke wrote:
>> I've added some tests for scipy.base.polynomial and
>> scipy.base.ufunclike, but I used doctests instead of writing out
>> something with unittest. They're run by using a test_suite(level)
>> function in the appropriate test module.
>>
>> They were much easier to write than using the unittest API: copy-and-
>> paste from my terminal window, mostly :-)
>>
>> I'm not familiar with the internals of scipy.test.testing, so I don't
>> know if there's something I'm missing when setting them up. It does
>> require Python 2.3 or higher to make a unittest test suite from the
>> doctest, though.
>>
>
> One problem is that the doctests screw up when
> ipython is used, e.g.:
>
> ipython
> import scipy
> scipy.__core_version__
> scipy.__core_config__.show()
> scipy.test(10)
>
> Giving many of this type.
>
> *****************************************************************
> Failure in example: p
> from line #5 of scipy.base.polynomial.test_polynomial
> Expected: poly1d([ 1.,  2.,  3.])
> Got:
> *****************************************************************
> Failure in example: q
> from line #11 of scipy.base.polynomial.test_polynomial
> Expected: poly1d([ 3.,  2.,  1.])
> Got:
>
>
> Note that I use IPython 0.6.13 and I vaguely
> remember that something like this
> was discussed on the IPython mailing list some time ago.

Fixed. There's some interaction with IPython's sys.displayhook that  
doctest doesn't like. Now, scipy.test will switch to the builtin  
displayhook (stored at sys.__displayhook__) before running tests.

-- 
|>|\/|<
/------------------------------------------------------------------\
|David M. Cooke              http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the Scipy-dev mailing list