diff options
author | xdegaye <xdegaye@gmail.com> | 2019-05-03 17:09:17 +0200 |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-05-03 08:09:17 -0700 |
commit | 4461d704e23a13dfbe78ea3020e4cbeff4b68dc2 (patch) | |
tree | c1747fb1ab5906ff40a41308d9221f0d39139bd2 | |
parent | a8a79cacca4a03e2e682bf10108c80f502791755 (diff) | |
download | cpython-git-4461d704e23a13dfbe78ea3020e4cbeff4b68dc2.tar.gz |
bpo-36341: Fix tests calling bind() on AF_UNIX sockets (GH-12399)
Those tests may fail with PermissionError.
https://bugs.python.org/issue36341
-rw-r--r-- | Lib/test/test_asyncio/test_server.py | 2 | ||||
-rw-r--r-- | Lib/test/test_socket.py | 9 | ||||
-rw-r--r-- | Lib/test/test_stat.py | 5 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Tests/2019-03-18-10-47-45.bpo-36341.UXlY0P.rst | 2 |
4 files changed, 13 insertions, 5 deletions
diff --git a/Lib/test/test_asyncio/test_server.py b/Lib/test/test_asyncio/test_server.py index 6de058a1e9..ab7f3debbc 100644 --- a/Lib/test/test_asyncio/test_server.py +++ b/Lib/test/test_asyncio/test_server.py @@ -73,7 +73,7 @@ class SelectorStartServerTests(BaseStartServer, unittest.TestCase): def new_loop(self): return asyncio.SelectorEventLoop() - @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'no Unix sockets') + @support.skip_unless_bind_unix_socket def test_start_unix_server_1(self): HELLO_MSG = b'1' * 1024 * 5 + b'\n' started = threading.Event() diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 815f9adce6..0094cecb79 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1796,8 +1796,13 @@ class GeneralModuleTests(unittest.TestCase): self.addCleanup(shutil.rmtree, tmpdir) s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.addCleanup(s.close) - s.bind(os.path.join(tmpdir, 'socket')) - self._test_socket_fileno(s, socket.AF_UNIX, socket.SOCK_STREAM) + try: + s.bind(os.path.join(tmpdir, 'socket')) + except PermissionError: + pass + else: + self._test_socket_fileno(s, socket.AF_UNIX, + socket.SOCK_STREAM) def test_socket_fileno_rejects_float(self): with self.assertRaisesRegex(TypeError, "integer argument expected"): diff --git a/Lib/test/test_stat.py b/Lib/test/test_stat.py index 38ff2bcf8a..17443bed07 100644 --- a/Lib/test/test_stat.py +++ b/Lib/test/test_stat.py @@ -2,7 +2,8 @@ import unittest import os import socket import sys -from test.support import TESTFN, import_fresh_module +from test.support import (TESTFN, import_fresh_module, + skip_unless_bind_unix_socket) c_stat = import_fresh_module('stat', fresh=['_stat']) py_stat = import_fresh_module('stat', blocked=['_stat']) @@ -192,7 +193,7 @@ class TestFilemode: self.assertS_IS("BLK", st_mode) break - @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix socket') + @skip_unless_bind_unix_socket def test_socket(self): with socket.socket(socket.AF_UNIX) as s: s.bind(TESTFN) diff --git a/Misc/NEWS.d/next/Tests/2019-03-18-10-47-45.bpo-36341.UXlY0P.rst b/Misc/NEWS.d/next/Tests/2019-03-18-10-47-45.bpo-36341.UXlY0P.rst new file mode 100644 index 0000000000..b76447d6cf --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-03-18-10-47-45.bpo-36341.UXlY0P.rst @@ -0,0 +1,2 @@ +Fix tests that may fail with PermissionError upon calling bind() on AF_UNIX +sockets. |