This little tip is quite helpful. Doctest mode in iPython has a lot of potential. iPython in general is pretty phenomenal.
Run your doctests from within IPython for development and debugging.
The special %doctest_mode command toggles a mode where
the prompt, output and exceptions display matches as closely as possible
that of the default Python interpreter. In addition, this mode allows
you to directly paste in code that contains leading `>>>‘
prompts, even if they have extra leading whitespace (as is common
in doctest files). This combined with the `%history -tn’
call to see your translated history (with these extra prompts removed
and no line numbers) allows for an easy doctest workflow, where you
can go from doctest to interactive execution to pasting into valid
Python code as needed.