diff options
Diffstat (limited to 'psutil')
-rw-r--r-- | psutil/tests/__init__.py | 10 | ||||
-rwxr-xr-x | psutil/tests/test_connections.py | 5 | ||||
-rwxr-xr-x | psutil/tests/test_contracts.py | 2 |
3 files changed, 10 insertions, 7 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 1fe583b5..5e4f37b3 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -35,6 +35,7 @@ from socket import AF_INET6 from socket import SOCK_STREAM import psutil +from psutil import AIX from psutil import MACOS from psutil import POSIX from psutil import SUNOS @@ -174,6 +175,7 @@ except Exception: HAS_SENSORS_FANS = hasattr(psutil, "sensors_fans") HAS_SENSORS_TEMPERATURES = hasattr(psutil, "sensors_temperatures") HAS_THREADS = hasattr(psutil.Process, "threads") +SKIP_SYSCONS = (MACOS or AIX) and os.getuid() != 0 # --- misc @@ -401,7 +403,7 @@ def create_zombie_proc(): with contextlib.closing(socket.socket(socket.AF_UNIX)) as sock: sock.settimeout(GLOBAL_TIMEOUT) sock.bind(unix_file) - sock.listen() + sock.listen(5) pyrun(src) conn, _ = sock.accept() try: @@ -896,7 +898,7 @@ def bind_socket(family=AF_INET, type=SOCK_STREAM, addr=None): sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(addr) if type == socket.SOCK_STREAM: - sock.listen() + sock.listen(5) return sock except Exception: sock.close() @@ -911,7 +913,7 @@ def bind_unix_socket(name, type=socket.SOCK_STREAM): try: sock.bind(name) if type == socket.SOCK_STREAM: - sock.listen() + sock.listen(5) except Exception: sock.close() raise @@ -924,7 +926,7 @@ def tcp_socketpair(family, addr=("", 0)): """ with contextlib.closing(socket.socket(family, SOCK_STREAM)) as ll: ll.bind(addr) - ll.listen() + ll.listen(5) addr = ll.getsockname() c = socket.socket(family, SOCK_STREAM) try: diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py index 12d417e3..5fda78cb 100755 --- a/psutil/tests/test_connections.py +++ b/psutil/tests/test_connections.py @@ -18,7 +18,6 @@ from socket import SOCK_DGRAM from socket import SOCK_STREAM import psutil -from psutil import AIX from psutil import FREEBSD from psutil import LINUX from psutil import MACOS @@ -41,6 +40,7 @@ from psutil.tests import pyrun from psutil.tests import reap_children from psutil.tests import safe_rmpath from psutil.tests import skip_on_access_denied +from psutil.tests import SKIP_SYSCONS from psutil.tests import tcp_socketpair from psutil.tests import TESTFN from psutil.tests import TRAVIS @@ -52,7 +52,6 @@ from psutil.tests import wait_for_file thisproc = psutil.Process() SOCK_SEQPACKET = getattr(socket, "SOCK_SEQPACKET", object()) -SKIP_SYSCONS = (MACOS or AIX) and os.getuid() != 0 class Base(object): @@ -417,7 +416,7 @@ class TestFilters(Base, unittest.TestCase): import socket, time s = socket.socket($family, socket.SOCK_STREAM) s.bind(('$addr', 0)) - s.listen() + s.listen(5) with open('$testfn', 'w') as f: f.write(str(s.getsockname()[:2])) time.sleep(60) diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py index ec86ba40..cb4a2b96 100755 --- a/psutil/tests/test_contracts.py +++ b/psutil/tests/test_contracts.py @@ -36,6 +36,7 @@ from psutil.tests import HAS_SENSORS_FANS from psutil.tests import HAS_SENSORS_TEMPERATURES from psutil.tests import is_namedtuple from psutil.tests import safe_rmpath +from psutil.tests import SKIP_SYSCONS from psutil.tests import TESTFN from psutil.tests import unittest from psutil.tests import VALID_PROC_STATUSES @@ -221,6 +222,7 @@ class TestSystem(unittest.TestCase): self.assertIsInstance(disk.fstype, str) self.assertIsInstance(disk.opts, str) + @unittest.skipIf(SKIP_SYSCONS, "requires root") def test_net_connections(self): with create_sockets(): ret = psutil.net_connections('all') |