In most cases a copy-and-paste of an interactive console session works fine--just make sure the leading whitespace is rigidly consistent (you can mix tabs and spaces if you're too lazy to do it right, but doctest is not in the business of guessing what you think a tab means).
>>> # comments are ignored >>> x = 12 >>> x 12 >>> if x == 13: ... print "yes" ... else: ... print "no" ... print "NO" ... print "NO!!!" ... no NO NO!!! >>>
Any expected output must immediately follow the final
'>
or >
> ''... '
line containing the code, and
the expected output (if any) extends to the next '>
or all-whitespace line.
>
> '
The fine print:
>>> if "yes" == \\ ... "y" + \\ ... "es": ... print 'yes' yes
>>> assert "Easy!" >>> import math >>> math.floor(1.9) 1.0
and as many leading whitespace characters are stripped from the
expected output as appeared in the initial '>
line
that triggered it.
>
> '
See About this document... for information on suggesting changes.