doctest

Tim Peters tim.one at comcast.net
Wed Mar 31 02:58:46 CEST 2004


[Thomas Heller]
> I've just read the 'Automating testing with doctest' pycon paper, and
> I'm exited about the future of doctest.

Cool!

> This simple script reads the ctypes docs written in StructuredText,
> and runs and tests the code examples in it:
>
> """
> import doctest
>
> ex = doctest._extract_examples(file("tutorial.stx").read())
> doctest._run_examples(ex, {}, 0, "tutorial.stx", 0, 0)
> """

Other kinds of wrappers are growing in the Zope3 project.  In fact, the new
ones added to Python 2.3 were originally written by Jim Fulton for Zope3.

> Do I understand correctly that the doctest-pretty printer will
> eventually remove the remaining 'warts', ie that doctest complains
> about the address part in this?
>
> >>> class X(object): pass
> ...
> >>> x = X()
> >>> x
> >>> <__main__.X object at 0x008FA3F0>

Probably, but it's a tradeoff:  doctest strove to be 100% WYSIWYG, and the
"doc" part of "doctest" does suffer when that fails.  In this case, I think
your example makes for poor documentation:  what are you really trying to
communicate?  If it's that X() creates an X object, then

>>> class X(object): pass
>>> x = X()
>>> type(x) is X
True

is a much cleaner statement.  Of course, if you're trying to illustrate that
Python's default repr() produces unpredictable output for class instances,
then it's a fine piece of documentation <wink>.

> And is it already available somewhere?

No.  It will most likely exist in Zope3 first.





More information about the Python-list mailing list