[Python-Dev] Purpose of Doctests [Was: Best practices for Enum]

Steven D'Aprano steve at pearwood.info
Mon May 20 15:32:10 CEST 2013

On 20/05/13 20:45, Antoine Pitrou wrote:
> On Sat, 18 May 2013 23:41:59 -0700
> Raymond Hettinger <raymond.hettinger at gmail.com> wrote:
>> We should continue to encourage users to make thorough unit tests
>> and to leave doctests for documentation.  That said, it should be
>> recognized that some testing is better than no testing.  And doctests
>> may be attractive in that regard because it is almost effortless to
>> cut-and-paste a snippet from the interactive prompt.  That isn't a
>> best practice, but it isn't a worst practice either.
> There are other reasons to hate doctest, such as the obnoxious
> error reporting.  Having to wade through ten pages of output to find
> what went wrong is no fun.

Ten pages of broken unit tests are no picnic either.

If you have ten pages of failures, then it doesn't matter *what* testing framework you use, you're going to have a bad time. But personally, I find doc test error reports perfectly clear and readable, and not overly verbose.

File "test.py", line 4, in __main__
Failed example:

That's even simpler than a traceback.

> Also the difficulty of editing them. For some reason, my editor doesn't
> offer me facilities to edit interactive prompt session snippets.

Your text editor doesn't allow you to edit text? Even Notepad allows that!

Seriously, what editor are you using that doesn't allow you to edit pasted snippets?


More information about the Python-Dev mailing list