Issue #7449, last part (11): fix many tests if thread support is disabled
* Use try/except ImportError or test_support.import_module() to import thread
and threading modules
* Add @unittest.skipUnless(threading, ...) to testcases using threads
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index 9a492f6..977a152 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -1,7 +1,6 @@
import asyncore
import email.utils
import socket
-import threading
import smtpd
import smtplib
import StringIO
@@ -9,9 +8,14 @@
import time
import select
-from unittest import TestCase
+import unittest
from test import test_support
+try:
+ import threading
+except ImportError:
+ threading = None
+
HOST = test_support.HOST
def server(evt, buf, serv):
@@ -36,7 +40,8 @@
serv.close()
evt.set()
-class GeneralTests(TestCase):
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class GeneralTests(unittest.TestCase):
def setUp(self):
self._threads = test_support.threading_setup()
@@ -138,7 +143,8 @@
# test server times out, causing the test to fail.
# Test behavior of smtpd.DebuggingServer
-class DebuggingServerTests(TestCase):
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class DebuggingServerTests(unittest.TestCase):
def setUp(self):
# temporarily replace sys.stdout to capture DebuggingServer output
@@ -233,7 +239,7 @@
self.assertEqual(self.output.getvalue(), mexpect)
-class NonConnectingTests(TestCase):
+class NonConnectingTests(unittest.TestCase):
def testNotConnected(self):
# Test various operations on an unconnected SMTP object that
@@ -254,7 +260,8 @@
# test response of client to a non-successful HELO message
-class BadHELOServerTests(TestCase):
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class BadHELOServerTests(unittest.TestCase):
def setUp(self):
self.old_stdout = sys.stdout
@@ -378,7 +385,8 @@
# Test various SMTP & ESMTP commands/behaviors that require a simulated server
# (i.e., something with more features than DebuggingServer)
-class SMTPSimTests(TestCase):
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class SMTPSimTests(unittest.TestCase):
def setUp(self):
self._threads = test_support.threading_setup()