[Python-checkins] bpo-35505: Skip test_imap4_host_default_value if localhost listens on IMAP port (GH-11823)

Miss Islington (bot) webhook-mailer at python.org
Tue Feb 12 13:54:36 EST 2019


https://github.com/python/cpython/commit/009220eae2e6b456707c1c89ef3f344b682e89d5
commit: 009220eae2e6b456707c1c89ef3f344b682e89d5
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-02-12T10:54:31-08:00
summary:

bpo-35505: Skip test_imap4_host_default_value if localhost listens on IMAP port (GH-11823)


Make test_imap4_host_default_value independent on whether the
local IMAP server is running.
(cherry picked from commit 3dc67d0316740e78e7cd014343f34d85908219b7)

Co-authored-by: Matěj Cepl <mcepl at cepl.eu>

files:
A Misc/NEWS.d/next/Tests/2019-02-12-01-33-08.bpo-35505.N9ba_K.rst
M Lib/test/test_imaplib.py

diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
index a0b598d0c784..a060143e1f6b 100644
--- a/Lib/test/test_imaplib.py
+++ b/Lib/test/test_imaplib.py
@@ -8,6 +8,7 @@
 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 @@ def test_that_Time2Internaldate_returns_a_result(self):
             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
index 000000000000..f1d48d612073
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-02-12-01-33-08.bpo-35505.N9ba_K.rst
@@ -0,0 +1,2 @@
+Make test_imap4_host_default_value independent on whether the 
+local IMAP server is running.



More information about the Python-checkins mailing list