#NEWLINE# def test_exception_function( self ) : #NEWLINE# #INDENT# def spam( state = [ 0 ] ) : #NEWLINE# #INDENT# i = state [ 0 ] #NEWLINE# state [ 0 ] = ( i + 1 ) #NEWLINE# if ( i == 10 ) : #NEWLINE# #INDENT# raise RuntimeError #NEWLINE# #UNINDENT# return i #NEWLINE# #UNINDENT# res = [ ] #NEWLINE# try : #NEWLINE# #INDENT# for x in iter ( spam , 20 ) : #NEWLINE# #INDENT# res . append ( self ) #NEWLINE# #UNINDENT# #UNINDENT# except RuntimeError : #NEWLINE# #INDENT# self . assertEqual ( res , list ( range ( 10 ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . fail ( 'should have raised RuntimeError' )