Ramblings

March 11, 2008

ipython, doctest, interactive testing

Filed under: dev, python — michaelangela @ 5:30 am

This little tip is quite helpful. Doctest mode in iPython has a lot of potential. iPython in general is pretty phenomenal.

Quick tips

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.

Advertisements

2 Comments »

  1. how about an example? in particular, I’d like to use verbose (-v) on a file to get full output.

    Comment by Scott Stornetta — November 25, 2013 @ 2:19 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: