From c2670aa13d8309b27a08141064ddc95330c88379 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 11 Oct 2016 19:00:48 -0700 Subject: [PATCH] unix files on OSX cann't be deleted due to perm err --- psutil/tests/test_process.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 2b90be2e3..00861ef3a 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -1044,10 +1044,10 @@ def check_conn(proc, conn, family, type, laddr, raddr, status, kinds): @skip_on_access_denied(only_if=OSX) def test_connections_unix(self): def check(type): - safe_rmpath(TESTFN) + tfile = tempfile.mktemp(prefix=TESTFILE_PREFIX) if OSX else TESTFN sock = socket.socket(AF_UNIX, type) with contextlib.closing(sock): - sock.bind(TESTFN) + sock.bind(tfile) cons = psutil.Process().connections(kind='unix') conn = cons[0] check_connection_ntuple(conn) @@ -1055,7 +1055,7 @@ def check(type): self.assertEqual(conn.fd, sock.fileno()) self.assertEqual(conn.family, AF_UNIX) self.assertEqual(conn.type, type) - self.assertEqual(conn.laddr, TESTFN) + self.assertEqual(conn.laddr, tfile) if not SUNOS: # XXX Solaris can't retrieve system-wide UNIX # sockets. @@ -1308,6 +1308,7 @@ def succeed_or_zombie_p_exc(fun, *args, **kwargs): # Both of them are supposed to be freed / killed by # reap_children() as they are attributable to 'us' # (os.getpid()) via children(recursive=True). + unix_file = tempfile.mktemp(prefix=TESTFILE_PREFIX) if OSX else TESTFN src = textwrap.dedent("""\ import os, sys, time, socket, contextlib child_pid = os.fork() @@ -1323,11 +1324,11 @@ def succeed_or_zombie_p_exc(fun, *args, **kwargs): else: pid = bytes(str(os.getpid()), 'ascii') s.sendall(pid) - """ % TESTFN) + """ % unix_file) with contextlib.closing(socket.socket(socket.AF_UNIX)) as sock: try: sock.settimeout(GLOBAL_TIMEOUT) - sock.bind(TESTFN) + sock.bind(unix_file) sock.listen(1) pyrun(src) conn, _ = sock.accept()