Skip to content

Commit 1d0f9b3

Browse files
authored
bpo-38614: Use test.support.INTERNET_TIMEOUT constant (GH-17565)
Replace hardcoded timeout constants in tests with INTERNET_TIMEOUT of test.support, so it's easier to ajdust this timeout for all tests at once.
1 parent c98b019 commit 1d0f9b3

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

Lib/test/test_nntplib.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
ssl = None
2020

2121

22-
TIMEOUT = 30
2322
certfile = os.path.join(os.path.dirname(__file__), 'keycert3.pem')
2423

2524
if ssl is not None:
@@ -270,12 +269,18 @@ def is_connected():
270269
return True
271270

272271
try:
273-
with self.NNTP_CLASS(self.NNTP_HOST, timeout=TIMEOUT, usenetrc=False) as server:
272+
server = self.NNTP_CLASS(self.NNTP_HOST,
273+
timeout=support.INTERNET_TIMEOUT,
274+
usenetrc=False)
275+
with server:
274276
self.assertTrue(is_connected())
275277
self.assertTrue(server.help())
276278
self.assertFalse(is_connected())
277279

278-
with self.NNTP_CLASS(self.NNTP_HOST, timeout=TIMEOUT, usenetrc=False) as server:
280+
server = self.NNTP_CLASS(self.NNTP_HOST,
281+
timeout=support.INTERNET_TIMEOUT,
282+
usenetrc=False)
283+
with server:
279284
server.quit()
280285
self.assertFalse(is_connected())
281286
except SSLError as ssl_err:
@@ -307,7 +312,8 @@ def setUpClass(cls):
307312
support.requires("network")
308313
with support.transient_internet(cls.NNTP_HOST):
309314
try:
310-
cls.server = cls.NNTP_CLASS(cls.NNTP_HOST, timeout=TIMEOUT,
315+
cls.server = cls.NNTP_CLASS(cls.NNTP_HOST,
316+
timeout=support.INTERNET_TIMEOUT,
311317
usenetrc=False)
312318
except SSLError as ssl_err:
313319
# matches "[SSL: DH_KEY_TOO_SMALL] dh key too small"

Lib/test/test_urllib2net.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
support.requires("network")
1212

13-
TIMEOUT = 60 # seconds
14-
1513

1614
def _retry_thrice(func, exc, *args, **kwargs):
1715
for i in range(3):
@@ -227,7 +225,7 @@ def _test_urls(self, urls, handlers, retry=True):
227225

228226
with support.transient_internet(url):
229227
try:
230-
f = urlopen(url, req, TIMEOUT)
228+
f = urlopen(url, req, support.INTERNET_TIMEOUT)
231229
# urllib.error.URLError is a subclass of OSError
232230
except OSError as err:
233231
if expected_err:

Lib/test/test_urllibnet.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
class URLTimeoutTest(unittest.TestCase):
1717
# XXX this test doesn't seem to test anything useful.
1818

19-
TIMEOUT = 30.0
20-
2119
def setUp(self):
22-
socket.setdefaulttimeout(self.TIMEOUT)
20+
socket.setdefaulttimeout(support.INTERNET_TIMEOUT)
2321

2422
def tearDown(self):
2523
socket.setdefaulttimeout(None)

0 commit comments

Comments
 (0)