[IPython-user] unittest'ing in iPython

Fernando Perez Fernando.Perez at colorado.edu
Fri May 13 12:46:42 CDT 2005

danny shevitz wrote:
> Howdy,
> I'm an IPython newbie, although an experienced python user. I tried
> searching the archives, but this is too frustrating being archived by
> month. Is there a fully searchable archive? BTW I'm running on Win2K,
> python 2.3.4, ipython 0.6.13.
> Here's the question: I use unittest'ing extensively. I want to unittest
> under IPython. If there is an exception I want to drop into the
> debugger at the point of that exception. The problem is that the
> unittesting framework catches all exceptions and deals with them
> nicely. Is there any way to enter the debugger if something fails in my
> unit tests? I have been trying the %run command, but to no avail. 

For this one, I'm not sure, but perhaps Alex's suggestions/code did help.

> A second question is again with unittest'ing. When I run in a dos
> prompt I get:
 > what's up with all the junk at the end? this is run with %pdb off

This is annoying enough that I've treated it as a bug.  It's understandable 
behavior, since unittest generates a SystemExit exception always, so ipython 
is giving you that traceback.  But there may be valid cases (such as this) 
where you may want to quiet out any SystemExit raised.  For that purpose, I've 
added a new '-e' flag to %run:

         -e: ignore sys.exit() calls or SystemExit exceptions in the script
         being run.  This is particularly useful if IPython is being used to
         run unittests, which always exit with a sys.exit() call.  In such
         cases you are interested in the output of the test results, not in
         seeing a traceback of the unittest module.

This will be part of the .14 bugfix release.

Thanks for the report,


More information about the IPython-user mailing list