def assertException( exceptionType, f, msg = None ):
    """Assert that an exception of type \var{exceptionType}
    is thrown when the function \var{f} is evaluated.
    """
    try:
        f()
    except exceptionType:
        assert True
    else:
        print >>sys.stderr, "Error: expected <%s> to be thrown by function%s" % ( exceptionType.__name__, colon( msg ) )
        traceback.print_stack()
Assert that an exception of type ar{exceptionType}
    is thrown when the function ar{f} is evaluated.
    
recipes/Python/577538_Poor_Man_unit_tests/recipe-577538.py