File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1171,6 +1171,25 @@ def test_basic(self):
11711171 self .assertEndsWith (data , '\n \n Hello \u2713 ' )
11721172 h .close ()
11731173
1174+ def test_connection_closed_on_send_failure (self ):
1175+ handler = logging .handlers .SMTPHandler (
1176+ ("localhost" , 25 ),
1177+ "me@example.com" ,
1178+ "you@example.com" ,
1179+ "subject" ,
1180+ timeout = self .TIMEOUT ,
1181+ )
1182+ record = logging .makeLogRecord ({"msg" : "hello" })
1183+
1184+ smtp = unittest .mock .Mock ()
1185+ smtp .send_message .side_effect = OSError ("send failed" )
1186+
1187+ with unittest .mock .patch ("smtplib.SMTP" , return_value = smtp ):
1188+ with support .captured_stderr ():
1189+ handler .emit (record )
1190+
1191+ smtp .close .assert_called_once ()
1192+
11741193 def process_message (self , * args ):
11751194 self .messages .append (args )
11761195 self .handled .set ()
You can’t perform that action at this time.
0 commit comments