A current limitation of doctest is that it can't handle output containing blank lines, since it uses blank lines to detect the end of the example. This patch adds a new option, END_WITH_DEDENT, that gets around that problem by using a dedent to detect the end of examples instead. In particular, when END_WITH_DEDENT is specified, the end of each indented doctest example is marked by a dedent past its original prompt (>>>). Thus, blank lines may appear within the output. However, trailing blank lines are still disallowed. Unindented docstring examples continue to be termined by a blank line (since dedenting past the prompt is impossible). Here's an example use: def f(): r""" A doctest example with a blank line: >>> print 'One\n\nTwo' One Two Note that ending with dedents also means that we can skip the blank lines around doctest examples if we want: >>> print 1 1 This dedent signifies the end of the example; there's no need for a blank line. """ The END_WITH_DEDENT uses the same optionflags system that is already used by DONT_ACCEPT_TRUE_FOR_1. The patch was made avainst revision 1.33 of doctest.py.
Logged In: YES user_id=195958 This patch is probably mutually exclusive with patch #933238 [1], since they both have the same goal: to allow blank lines in doctest output. I thought of this solution first, but I think I prefer the other patch. Here's a comparison of pros and cons of this patch vs #933238. [-] it needs a special option to turn it on [-] it doesn't handles trailing blank lines [-] it will break external tools like epytext and restructuredtext that look for doctest blocks. [+] the user doesn't have to manually add blank line markers.