bpo-32680 add default "sock" on SMTP objects (#5345)

By default the smtplib.SMTP objects did not have a sock attribute, it
was only created during connect()
This commit is contained in:
Romuald Brunet 2018-10-09 16:31:55 +02:00 committed by Giampaolo Rodola
parent 2b2758d0b3
commit 7b31397180
3 changed files with 11 additions and 1 deletions

View file

@ -602,6 +602,13 @@ class NonConnectingTests(unittest.TestCase):
self.assertRaises(OSError, smtplib.SMTP,
"localhost:bogus")
def testSockAttributeExists(self):
# check that sock attribute is present outside of a connect() call
# (regression test, the previous behavior raised an
# AttributeError: 'SMTP' object has no attribute 'sock')
with smtplib.SMTP() as smtp:
self.assertIsNone(smtp.sock)
class DefaultArgumentsTests(unittest.TestCase):