summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-09-30 12:22:52 -0400
committerGitHub <noreply@github.com>2016-09-30 12:22:52 -0400
commitf6fe8ecc10a3d88470e25fe6ebc61122154653f0 (patch)
treea74fdc1708ce2599de0385aed2141770040606d0
parentfc92c6b5000179145ec633a70f380a0a109381c3 (diff)
Refs #27210 -- Fixed isolation of test_fail_silently_on_connection_error.
The test wouldn't pass if a mail server is running on the system.
-rw-r--r--tests/mail/tests.py44
1 files changed, 21 insertions, 23 deletions
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index 1bb7236032..e680fb165a 100644
--- a/tests/mail/tests.py
+++ b/tests/mail/tests.py
@@ -1449,9 +1449,6 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):
finally:
SMTP.send = send
-
-class SMTPNoServerTests(SimpleTestCase):
-
def test_send_messages_after_open_failed(self):
"""
send_messages() shouldn't try to send messages if open() raises an
@@ -1465,30 +1462,31 @@ class SMTPNoServerTests(SimpleTestCase):
email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'])
self.assertEqual(backend.send_messages([email]), None)
- def test_fail_silently_on_connection_error(self):
- """
- A socket connection error is silenced with fail_silently=True.
- """
- backend = smtp.EmailBackend(username='', password='')
- with self.assertRaises(socket.error):
- backend.open()
- backend.fail_silently = True
- backend.open()
-
-class SMTPBackendStoppedServerTest(SMTPBackendTestsBase):
+class SMTPBackendStoppedServerTests(SMTPBackendTestsBase):
"""
- This test requires a separate class, because it shuts down the
- FakeSMTPServer started in setUpClass(). It cannot be restarted
- ("RuntimeError: threads can only be started once").
+ These tests require a separate class, because the FakeSMTPServer is shut
+ down in setUpClass(), and it cannot be restarted ("RuntimeError: threads
+ can only be started once").
"""
+ @classmethod
+ def setUpClass(cls):
+ super(SMTPBackendStoppedServerTests, cls).setUpClass()
+ cls.backend = smtp.EmailBackend(username='', password='')
+ cls.server.stop()
def test_server_stopped(self):
"""
- Test that closing the backend while the SMTP server is stopped doesn't
- raise an exception.
+ Closing the backend while the SMTP server is stopped doesn't raise an
+ exception.
"""
- backend = smtp.EmailBackend(username='', password='')
- backend.open()
- self.server.stop()
- backend.close()
+ self.backend.close()
+
+ def test_fail_silently_on_connection_error(self):
+ """
+ A socket connection error is silenced with fail_silently=True.
+ """
+ with self.assertRaises(socket.error):
+ self.backend.open()
+ self.backend.fail_silently = True
+ self.backend.open()