]> granicus.if.org Git - python/commitdiff
bpo-35505: Skip test_imap4_host_default_value if localhost listens on IMAP port ...
authorMatěj Cepl <mcepl@cepl.eu>
Tue, 12 Feb 2019 18:30:19 +0000 (19:30 +0100)
committerVictor Stinner <vstinner@redhat.com>
Tue, 12 Feb 2019 18:30:19 +0000 (19:30 +0100)
Make test_imap4_host_default_value independent on whether the
local IMAP server is running.

Lib/test/test_imaplib.py
Misc/NEWS.d/next/Tests/2019-02-12-01-33-08.bpo-35505.N9ba_K.rst [new file with mode: 0644]

index a0b598d0c7840926a4aeba5458b411021ee1b5aa..a060143e1f6be4327d342a06bd26ac41f0d559a4 100644 (file)
@@ -8,6 +8,7 @@ import socketserver
 import time
 import calendar
 import threading
+import socket
 
 from test.support import (reap_threads, verbose, transient_internet,
                           run_with_tz, run_with_locale, cpython_only)
@@ -71,6 +72,15 @@ class TestImaplib(unittest.TestCase):
             imaplib.Time2Internaldate(t)
 
     def test_imap4_host_default_value(self):
+        # Check whether the IMAP4_PORT is truly unavailable.
+        with socket.socket() as s:
+            try:
+                s.connect(('', imaplib.IMAP4_PORT))
+                self.skipTest(
+                    "Cannot run the test with local IMAP server running.")
+            except socket.error:
+                pass
+
         expected_errnos = [
             # This is the exception that should be raised.
             errno.ECONNREFUSED,
diff --git a/Misc/NEWS.d/next/Tests/2019-02-12-01-33-08.bpo-35505.N9ba_K.rst b/Misc/NEWS.d/next/Tests/2019-02-12-01-33-08.bpo-35505.N9ba_K.rst
new file mode 100644 (file)
index 0000000..f1d48d6
--- /dev/null
@@ -0,0 +1,2 @@
+Make test_imap4_host_default_value independent on whether the 
+local IMAP server is running.