From: Martin Panter Date: Sat, 24 Dec 2016 10:41:37 +0000 (+0000) Subject: Issue #28815: Skip TIPC tests if /proc/modules is not readable X-Git-Tag: v3.5.3rc1~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e9ae5f9b1673145eb81f1a19860b3d7a2decfd9c;p=thirdparty%2FPython%2Fcpython.git Issue #28815: Skip TIPC tests if /proc/modules is not readable Based on patch by Patrila. --- diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index dbfcab8f6feb..ea3ca28a3995 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4717,9 +4717,17 @@ def isTipcAvailable(): """ if not hasattr(socket, "AF_TIPC"): return False - if not os.path.isfile("/proc/modules"): - return False - with open("/proc/modules") as f: + 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 (errno.ENOENT, errno.EISDIR, errno.EACCES): + return False + else: + raise + with f: for line in f: if line.startswith("tipc "): return True