bpo-40275: Avoid importing socket in test.support (GH-19603)

* Move socket related functions from test.support to socket_helper.
* Import socket, nntplib and urllib.error lazily in transient_internet().
* Remove importing multiprocess.
This commit is contained in:
Serhiy Storchaka 2020-04-25 10:06:29 +03:00 committed by GitHub
parent 3c8a5b459d
commit 16994912c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 472 additions and 429 deletions

View file

@ -10,6 +10,7 @@ import re
import threading
from test import support
from test.support import socket_helper
from nntplib import NNTP, GroupInfo
import nntplib
from unittest.mock import patch
@ -1555,14 +1556,14 @@ class MockSslTests(MockSocketTests):
class LocalServerTests(unittest.TestCase):
def setUp(self):
sock = socket.socket()
port = support.bind_port(sock)
port = socket_helper.bind_port(sock)
sock.listen()
self.background = threading.Thread(
target=self.run_server, args=(sock,))
self.background.start()
self.addCleanup(self.background.join)
self.nntp = NNTP(support.HOST, port, usenetrc=False).__enter__()
self.nntp = NNTP(socket_helper.HOST, port, usenetrc=False).__enter__()
self.addCleanup(self.nntp.__exit__, None, None, None)
def run_server(self, sock):