diff options
author | xdegaye <xdegaye@gmail.com> | 2017-11-24 16:35:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-24 16:35:55 (GMT) |
commit | 0f86cd38f4a38f25a4aed3759a654a4b7fa49031 (patch) | |
tree | dbf1b69d6ba27e7ff77221cd97ebae60ee962a61 /Lib/test/support | |
parent | 19fb134185ce155bc53f517116fca73093ba55e9 (diff) | |
download | cpython-0f86cd38f4a38f25a4aed3759a654a4b7fa49031.zip cpython-0f86cd38f4a38f25a4aed3759a654a4b7fa49031.tar.gz cpython-0f86cd38f4a38f25a4aed3759a654a4b7fa49031.tar.bz2 |
bpo-28684: asyncio tests handle PermissionError raised on binding unix sockets (GH-4503)
The test.support.skip_unless_bind_unix_socket() decorator is used to skip
asyncio tests that fail because the platform lacks a functional bind()
function for unix domain sockets (as it is the case for non root users on the
recent Android versions that run now SELinux in enforcing mode).
Diffstat (limited to 'Lib/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index b7cbdc6..e864896 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -88,6 +88,7 @@ __all__ = [ "requires_IEEE_754", "skip_unless_xattr", "requires_zlib", "anticipate_failure", "load_package_tests", "detect_api_mismatch", "check__all__", "requires_android_level", "requires_multiprocessing_queue", + "skip_unless_bind_unix_socket", # sys "is_jython", "is_android", "check_impl_detail", "unix_shell", "setswitchinterval", @@ -2432,6 +2433,28 @@ def skip_unless_xattr(test): msg = "no non-broken extended attribute support" return test if ok else unittest.skip(msg)(test) +_bind_nix_socket_error = None +def skip_unless_bind_unix_socket(test): + """Decorator for tests requiring a functional bind() for unix sockets.""" + if not hasattr(socket, 'AF_UNIX'): + return unittest.skip('No UNIX Sockets')(test) + global _bind_nix_socket_error + if _bind_nix_socket_error is None: + path = TESTFN + "can_bind_unix_socket" + with socket.socket(socket.AF_UNIX) as sock: + try: + sock.bind(path) + _bind_nix_socket_error = False + except OSError as e: + _bind_nix_socket_error = e + finally: + unlink(path) + if _bind_nix_socket_error: + msg = 'Requires a functional unix bind(): %s' % _bind_nix_socket_error + return unittest.skip(msg)(test) + else: + return test + def fs_is_case_insensitive(directory): """Detects if the file system for the specified directory is case-insensitive.""" |