diff -r 876bee0bd0ba Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4779,12 +4779,21 @@ """ if not hasattr(socket, "AF_TIPC"): return False - if not os.path.isfile("/proc/modules"): - return False - with open("/proc/modules") as f: - for line in f: - if line.startswith("tipc "): - return True + try: + f = open("/proc/modules") + except IOError as e: + # It's ok if the file does not exist, is a directory or if we + # have not the permission to read it. In any other case it's a + # real error, so raise it again. + if e.errno in (ENOENT, EISDIR, EACCES): + return False + else: + raise + else: + with f: + for line in f: + if line.startswith("tipc "): + return True return False @unittest.skipUnless(isTipcAvailable(),