Commit 4461d704 authored by xdegaye's avatar xdegaye Committed by Miss Islington (bot)

bpo-36341: Fix tests calling bind() on AF_UNIX sockets (GH-12399)



Those tests may fail with PermissionError.



https://bugs.python.org/issue36341
parent a8a79cac
...@@ -73,7 +73,7 @@ class SelectorStartServerTests(BaseStartServer, unittest.TestCase): ...@@ -73,7 +73,7 @@ class SelectorStartServerTests(BaseStartServer, unittest.TestCase):
def new_loop(self): def new_loop(self):
return asyncio.SelectorEventLoop() 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): def test_start_unix_server_1(self):
HELLO_MSG = b'1' * 1024 * 5 + b'\n' HELLO_MSG = b'1' * 1024 * 5 + b'\n'
started = threading.Event() started = threading.Event()
......
...@@ -1796,8 +1796,13 @@ class GeneralModuleTests(unittest.TestCase): ...@@ -1796,8 +1796,13 @@ class GeneralModuleTests(unittest.TestCase):
self.addCleanup(shutil.rmtree, tmpdir) self.addCleanup(shutil.rmtree, tmpdir)
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.addCleanup(s.close) self.addCleanup(s.close)
s.bind(os.path.join(tmpdir, 'socket')) try:
self._test_socket_fileno(s, socket.AF_UNIX, socket.SOCK_STREAM) 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): def test_socket_fileno_rejects_float(self):
with self.assertRaisesRegex(TypeError, "integer argument expected"): with self.assertRaisesRegex(TypeError, "integer argument expected"):
......
...@@ -2,7 +2,8 @@ import unittest ...@@ -2,7 +2,8 @@ import unittest
import os import os
import socket import socket
import sys 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']) c_stat = import_fresh_module('stat', fresh=['_stat'])
py_stat = import_fresh_module('stat', blocked=['_stat']) py_stat = import_fresh_module('stat', blocked=['_stat'])
...@@ -192,7 +193,7 @@ class TestFilemode: ...@@ -192,7 +193,7 @@ class TestFilemode:
self.assertS_IS("BLK", st_mode) self.assertS_IS("BLK", st_mode)
break break
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix socket') @skip_unless_bind_unix_socket
def test_socket(self): def test_socket(self):
with socket.socket(socket.AF_UNIX) as s: with socket.socket(socket.AF_UNIX) as s:
s.bind(TESTFN) s.bind(TESTFN)
......
Fix tests that may fail with PermissionError upon calling bind() on AF_UNIX
sockets.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment