#2653·psutil

[Linux] TestSystemAPIs.test_users 失败,因为 who -u 显示了 2 个 root 用户

作者: hroncok创建于 2025年10月21日更新于 2026年9月26日
标签buglinux

__________________________ TestSystemAPIs.test_users ___________________________

self = <psutil.tests.test_posix.TestSystemAPIs testMethod=test_users>

@retry_on_failure() def test_users(self): out = sh("who -u") if not out.strip(): raise pytest.skip("no users on this system") susers = [] for line in out.splitlines(): user = line.split()[0] terminal = line.split()[1] if LINUX or MACOS: try: pid = int(line.split()[-2]) except ValueError: pid = int(line.split()[-1]) susers.append((user, terminal, pid)) else: susers.append((user, terminal)) if LINUX or MACOS: pusers = [(u.name, u.terminal, u.pid) for u in psutil.users()] else: pusers = [(u.name, u.terminal) for u in psutil.users()] assert len(susers) == len(pusers) /usr/lib64/python3.14/site-packages/psutil/tests/test_posix.py:383: AssertionError

内容来源: giampaolo/psutil