Skip to content

Commit d6a8a72

Browse files
committed
stabilize some tests
1 parent 6ee112e commit d6a8a72

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

psutil/tests/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ def assert_proc_gone(self, proc):
10711071
self.assert_pid_gone(proc.pid)
10721072
ns = process_namespace(proc)
10731073
for fun, name in ns.iter(ns.all, clear_cache=True):
1074-
with self.subTest(proc=proc, name=name):
1074+
with self.subTest(proc=str(proc), name=name):
10751075
try:
10761076
ret = fun()
10771077
except psutil.ZombieProcess:
@@ -1109,7 +1109,7 @@ def assert_proc_zombie(self, proc):
11091109
# Call all methods.
11101110
ns = process_namespace(proc)
11111111
for fun, name in ns.iter(ns.all, clear_cache=True):
1112-
with self.subTest(proc=proc, name=name):
1112+
with self.subTest(proc=str(proc), name=name):
11131113
try:
11141114
fun()
11151115
except (psutil.ZombieProcess, psutil.AccessDenied) as exc:

psutil/tests/test_misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def check(ret):
255255

256256
ns = process_namespace(proc)
257257
for fun, name in ns.iter(ns.getters, clear_cache=True):
258-
with self.subTest(proc=proc, name=name):
258+
with self.subTest(proc=str(proc), name=name):
259259
try:
260260
ret = fun()
261261
except psutil.Error:

psutil/tests/test_posix.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,23 +356,36 @@ def test_nic_names(self):
356356
f" output\n{output}"
357357
)
358358

359-
# @pytest.mark.skipif(CI_TESTING and not psutil.users(),
360-
# reason="unreliable on CI")
361359
@retry_on_failure()
362360
def test_users(self):
363361
out = sh("who -u")
364362
if not out.strip():
365363
raise pytest.skip("no users on this system")
366-
lines = out.split('\n')
367-
users = [x.split()[0] for x in lines]
368-
terminals = [x.split()[1] for x in lines]
369-
assert len(users) == len(psutil.users())
370-
with self.subTest(psutil=psutil.users(), who=out):
371-
for idx, u in enumerate(psutil.users()):
372-
assert u.name == users[idx]
373-
assert u.terminal == terminals[idx]
374-
if u.pid is not None: # None on OpenBSD
375-
psutil.Process(u.pid)
364+
365+
susers = []
366+
for line in out.splitlines():
367+
user = line.split()[0]
368+
terminal = line.split()[1]
369+
if LINUX or MACOS:
370+
try:
371+
pid = int(line.split()[-2])
372+
except ValueError:
373+
pid = int(line.split()[-1])
374+
susers.append((user, terminal, pid))
375+
else:
376+
susers.append((user, terminal))
377+
378+
if LINUX or MACOS:
379+
pusers = [(u.name, u.terminal, u.pid) for u in psutil.users()]
380+
else:
381+
pusers = [(u.name, u.terminal) for u in psutil.users()]
382+
383+
assert len(susers) == len(pusers)
384+
assert sorted(susers) == sorted(pusers)
385+
386+
for user in psutil.users():
387+
if user.pid is not None:
388+
assert user.pid > 0
376389

377390
@retry_on_failure()
378391
def test_users_started(self):

psutil/tests/test_process_all.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,5 +530,4 @@ def check(pid):
530530
# Process class and is querable like a PID (process
531531
# ID). Skip it.
532532
continue
533-
with self.subTest(pid=pid):
534-
check(pid)
533+
check(pid)

psutil/tests/test_unicode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class TestFSAPIsWithInvalidPath(TestFSAPIs):
287287
funky_suffix = INVALID_UNICODE_SUFFIX
288288

289289
def expect_exact_path_match(self):
290-
return True
290+
return not MACOS
291291

292292

293293
# ===================================================================

0 commit comments

Comments
 (0)