Skip to content

Commit 4461d70

Browse files
xdegayemiss-islington
authored andcommitted
bpo-36341: Fix tests calling bind() on AF_UNIX sockets (GH-12399)
Those tests may fail with PermissionError. https://bugs.python.org/issue36341
1 parent a8a79ca commit 4461d70

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

Lib/test/test_asyncio/test_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SelectorStartServerTests(BaseStartServer, unittest.TestCase):
7373
def new_loop(self):
7474
return asyncio.SelectorEventLoop()
7575

76-
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'no Unix sockets')
76+
@support.skip_unless_bind_unix_socket
7777
def test_start_unix_server_1(self):
7878
HELLO_MSG = b'1' * 1024 * 5 + b'\n'
7979
started = threading.Event()

Lib/test/test_socket.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,8 +1796,13 @@ def test_socket_fileno(self):
17961796
self.addCleanup(shutil.rmtree, tmpdir)
17971797
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
17981798
self.addCleanup(s.close)
1799-
s.bind(os.path.join(tmpdir, 'socket'))
1800-
self._test_socket_fileno(s, socket.AF_UNIX, socket.SOCK_STREAM)
1799+
try:
1800+
s.bind(os.path.join(tmpdir, 'socket'))
1801+
except PermissionError:
1802+
pass
1803+
else:
1804+
self._test_socket_fileno(s, socket.AF_UNIX,
1805+
socket.SOCK_STREAM)
18011806

18021807
def test_socket_fileno_rejects_float(self):
18031808
with self.assertRaisesRegex(TypeError, "integer argument expected"):

Lib/test/test_stat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import os
33
import socket
44
import sys
5-
from test.support import TESTFN, import_fresh_module
5+
from test.support import (TESTFN, import_fresh_module,
6+
skip_unless_bind_unix_socket)
67

78
c_stat = import_fresh_module('stat', fresh=['_stat'])
89
py_stat = import_fresh_module('stat', blocked=['_stat'])
@@ -192,7 +193,7 @@ def test_devices(self):
192193
self.assertS_IS("BLK", st_mode)
193194
break
194195

195-
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix socket')
196+
@skip_unless_bind_unix_socket
196197
def test_socket(self):
197198
with socket.socket(socket.AF_UNIX) as s:
198199
s.bind(TESTFN)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix tests that may fail with PermissionError upon calling bind() on AF_UNIX
2+
sockets.

0 commit comments

Comments
 (0)