Timofei Shatrov wrote:
> But, you have to admit that it looks horrible (at least at the first glance). 
> If
> there's some programming style that I absolutely can't stand, it would be the
> one where programmer writes a huge block of commentary describing what a
> function does, followed by one-liner of code

You Sir, are no fan of Literate Programming :-).

> information in itself. With doctest it is even worse, because examples also
> contain superfluous information. Everyone can just copy-paste the code in REPL
> and see what happens when you execute it.

And doctest automates such REPL tests. Like macros, don't knock it till
you try it.

> Besides that, there are many reasons
> why tests should be stored in a separate file, or at least not in the same
> function that they are testing.

You need not have doctest as a part of source code. You can also create
a separate documentation file that contains prose as well as tests
intervening.

http://www.python.org/doc/lib/doctest-simple-testfile.html

Combine it with ReStructured Text and you have a wonderful
documentation and testing solution in one place. Personally, I like
this a lot better than Javadoc style documentation where usage examples
are often absent.

> Also Wikipedia article contains some "Cons of doctest" that look pretty nasty:

Of course, doctest is hardly the ultimate testing solution. But it does
an admirable job for many cases where you don't need to setup elaborate
tests.

> It's not surprising that no one uses this stuff for serious work.

I have seen enough libraries that use doctest. Zope, Twisted and Paste
are some of the popular Python projects in that use it. Epydoc supports
it as well.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to