File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -1163,6 +1163,56 @@ class E(Exception):
1163
1163
self .assertIs (b .__context__ , a )
1164
1164
self .assertIs (a .__context__ , c )
1165
1165
1166
+ def test_context_of_exception_in_try_and_finally (self ):
1167
+ try :
1168
+ try :
1169
+ te = TypeError (1 )
1170
+ raise te
1171
+ finally :
1172
+ ve = ValueError (2 )
1173
+ raise ve
1174
+ except Exception as e :
1175
+ exc = e
1176
+
1177
+ self .assertIs (exc , ve )
1178
+ self .assertIs (exc .__context__ , te )
1179
+
1180
+ def test_context_of_exception_in_except_and_finally (self ):
1181
+ try :
1182
+ try :
1183
+ te = TypeError (1 )
1184
+ raise te
1185
+ except :
1186
+ ve = ValueError (2 )
1187
+ raise ve
1188
+ finally :
1189
+ oe = OSError (3 )
1190
+ raise oe
1191
+ except Exception as e :
1192
+ exc = e
1193
+
1194
+ self .assertIs (exc , oe )
1195
+ self .assertIs (exc .__context__ , ve )
1196
+ self .assertIs (exc .__context__ .__context__ , te )
1197
+
1198
+ def test_context_of_exception_in_else_and_finally (self ):
1199
+ try :
1200
+ try :
1201
+ pass
1202
+ except :
1203
+ pass
1204
+ else :
1205
+ ve = ValueError (1 )
1206
+ raise ve
1207
+ finally :
1208
+ oe = OSError (2 )
1209
+ raise oe
1210
+ except Exception as e :
1211
+ exc = e
1212
+
1213
+ self .assertIs (exc , oe )
1214
+ self .assertIs (exc .__context__ , ve )
1215
+
1166
1216
def test_unicode_change_attributes (self ):
1167
1217
# See issue 7309. This was a crasher.
1168
1218
You can’t perform that action at this time.
0 commit comments