[Python-ideas] doctest

Nick Coghlan ncoghlan at gmail.com
Tue Feb 28 01:15:19 CET 2012

On Tue, Feb 28, 2012 at 9:44 AM, Ian Bicking <ianb at colorstudy.com> wrote:
> Just an implementation suggestion - Guido's suggestion of using
> sys.displayhook will work to change the repr of objects (I had never heard
> of it until then, and had to test to convince myself).  Doctest needs
> reliable repr's more than reversable repr's, and you can create them using
> that.  You'll still get a lot of <foobar.Foobar object at 0x391a9df>
> strings, which suck... but if you are committed to doctest then maybe better
> to provide good __repr__ methods on your custom objects!  For doctest.js
> (where I implemented a number of changes I would have wanted for doctest in
> Python) I have found this sort of thing sufficient, but Javascript objects
> tend to be a little more bare and there aren't existing conventions for
> repr/print/etc, so I have some more flexibility in my implementation.

You can actually do some pretty cool doctest hacks via displayhook and
excepthook. I created a hacked together doctest variant [1] years ago
that could run doctests from ODT files and also pay attention to
sys.excepthook/displayhook before deciding that the test had failed.

[1] http://svn.python.org/view/sandbox/trunk/userref/


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list