From 2d5d01f26ba7939e8a035b6fe7abcc8490c9f208 Mon Sep 17 00:00:00 2001
From: "Miss Islington (bot)"
 <31488909+miss-islington@users.noreply.github.com>
Date: Tue, 24 May 2022 17:42:06 -0700
Subject: [PATCH] test.pythoninfo no longer requires socket (GH-93191)

test.pythoninfo no longer fails if "import socket" fails: the socket
module is now optional.
(cherry picked from commit 4a31ed8a32699973ae1f779022794fdab9fa08ee)

Co-authored-by: Victor Stinner <vstinner@python.org>
---
 Lib/test/pythoninfo.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py
index 8c8011b550a..005eae549cb 100644
--- a/Lib/test/pythoninfo.py
+++ b/Lib/test/pythoninfo.py
@@ -532,7 +532,10 @@ def format_attr(attr, value):
 
 
 def collect_socket(info_add):
-    import socket
+    try:
+        import socket
+    except ImportError:
+        return
 
     hostname = socket.gethostname()
     info_add('socket.hostname', hostname)
-- 
GitLab