summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-08-02 13:09:45 (GMT)
committerGitHub <noreply@github.com>2024-08-02 13:09:45 (GMT)
commitc5655aa6ad120d2ed7f255bebd6e8b71a9c07dde (patch)
treea6d462739410263b12c282133e308a7afe86e28f /Lib/test/test_socket.py
parent5f90abaa786f994db3907fc31e2ee00ea2cf0929 (diff)
downloadcpython-c5655aa6ad120d2ed7f255bebd6e8b71a9c07dde.zip
cpython-c5655aa6ad120d2ed7f255bebd6e8b71a9c07dde.tar.gz
cpython-c5655aa6ad120d2ed7f255bebd6e8b71a9c07dde.tar.bz2
[3.11] gh-122133: Rework pure Python socketpair tests to avoid use of importlib.reload. (GH-122493) (GH-122506)
(cherry picked from commit f071f01b7b7e19d7d6b3a4b0ec62f820ecb14660) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py20
1 files changed, 6 insertions, 14 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index a60eb43..cc803d8 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -4676,7 +4676,6 @@ class BasicSocketPairTest(SocketPairTest):
class PurePythonSocketPairTest(SocketPairTest):
-
# Explicitly use socketpair AF_INET or AF_INET6 to ensure that is the
# code path we're using regardless platform is the pure python one where
# `_socket.socketpair` does not exist. (AF_INET does not work with
@@ -4691,28 +4690,21 @@ class PurePythonSocketPairTest(SocketPairTest):
# Local imports in this class make for easy security fix backporting.
def setUp(self):
- import _socket
- self._orig_sp = getattr(_socket, 'socketpair', None)
- if self._orig_sp is not None:
+ if hasattr(_socket, "socketpair"):
+ self._orig_sp = socket.socketpair
# This forces the version using the non-OS provided socketpair
# emulation via an AF_INET socket in Lib/socket.py.
- del _socket.socketpair
- import importlib
- global socket
- socket = importlib.reload(socket)
+ socket.socketpair = socket._fallback_socketpair
else:
- pass # This platform already uses the non-OS provided version.
+ # This platform already uses the non-OS provided version.
+ self._orig_sp = None
super().setUp()
def tearDown(self):
super().tearDown()
- import _socket
if self._orig_sp is not None:
# Restore the default socket.socketpair definition.
- _socket.socketpair = self._orig_sp
- import importlib
- global socket
- socket = importlib.reload(socket)
+ socket.socketpair = self._orig_sp
def test_recv(self):
msg = self.serv.recv(1024)