[Python-Dev] doctest improvements

Tim Peters tim.one at comcast.net
Mon May 31 22:00:17 EDT 2004


[Edward Loper]
> Perhaps you'd be happier with a different value of BLANKLINE_MARKER,
> then?  E.g. "blank>":
>
> def test():
>      r"""
>      A different marker:
>
>      >>> print 'a\n\nb'
>              a
>        blank>
>              b
>      """
>
> Although this means that you have to indent the doctest quite far.
> Perhaps it would be better if I changed the patch so the marker doesn't
> need to dedented all the way?  E.g.:
>
> def test():
>      r"""
>      A different marker:
>
>      >>> print 'a\n\nb'
>          a
>        <blank line>
>          b
>      """

That's more what I had in mind, but if the marker is changed to something
wordy instead of "a magic character", I don't think the dedent trick is of
much value anymore:

     r"""
     A different marker:

             >>> print 'a\n\nb'
             a
             <blank line>
             b
     """

Then when the expected output is (exactly) "<blank line>", doctest would
accept "<blank line>", or a line with nothing other than whitespace, as a
match.  I can't get upset by that bit of ambiguity.  The primary advantage
is that the implementation is then trivial, to write, document, and
understand.  It won't break external tools, and caters to leading, trailing,
and embedded blank lines.  It needs an option flag to turn it off, akin to
the current doctest.DONT_ACCEPT_TRUE_FOR_1 (the only non-wysiwyg gimmick
implemented now); it should be enabled by default.

> Another option to consider might be:
>
> def test():
>      r"""
>      A different marker:
>
>      >>> print 'a\n\nb'
>>   | a
>>   |
>>   | b
>      """
>
> I.e., the user can optionally preceed each line with a "|" (or some other
> marker), dedented past the prompt, to mark the extent of the output.  I
> don't think this looks as wysiwyg, though.

Nope, it sure doesn't.





More information about the Python-Dev mailing list