Skip to content

Commit 3dc67d0

Browse files
mceplvstinner
authored andcommitted
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.
1 parent 16f842d commit 3dc67d0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Lib/test/test_imaplib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import time
99
import calendar
1010
import threading
11+
import socket
1112

1213
from test.support import (reap_threads, verbose, transient_internet,
1314
run_with_tz, run_with_locale, cpython_only)
@@ -71,6 +72,15 @@ def test_that_Time2Internaldate_returns_a_result(self):
7172
imaplib.Time2Internaldate(t)
7273

7374
def test_imap4_host_default_value(self):
75+
# Check whether the IMAP4_PORT is truly unavailable.
76+
with socket.socket() as s:
77+
try:
78+
s.connect(('', imaplib.IMAP4_PORT))
79+
self.skipTest(
80+
"Cannot run the test with local IMAP server running.")
81+
except socket.error:
82+
pass
83+
7484
expected_errnos = [
7585
# This is the exception that should be raised.
7686
errno.ECONNREFUSED,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make test_imap4_host_default_value independent on whether the
2+
local IMAP server is running.

0 commit comments

Comments
 (0)