#2653·psutil

[Linux] TestSystemAPIs.test_users fails as who -u reports 2 root users

Author: hroncokCreated Oct 21, 2025Updated Sep 26, 2026
Labelsbuglinux

Summary

  • OS: Fedora Linux 44
  • Architecture: 64bit x86_64
  • Psutil version: 7.0.0+
  • Python version: 3.14.0
  • Type: tests

Description

I've noticed this test failure on the Fedora CI system with psutil 7.0.0:

__________________________ 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")
        lines = out.split('\n')
        users = [x.split()[0] for x in lines]
        terminals = [x.split()[1] for x in lines]
>       assert len(users) == len(psutil.users())
E       AssertionError: assert 2 == 1
E        +  where 2 = len(['root', 'root'])
E        +  and   1 = len([suser(name='root', terminal='pts/0', host='18.222.135.126', started=1761068965.0, pid=2783)])
E        +    where [suser(name='root', terminal='pts/0', host='18.222.135.126', started=1761068965.0, pid=2783)] = <function users at 0x7f3b3fa62610>()
E        +      where <function users at 0x7f3b3fa62610> = psutil.users

/usr/lib64/python3.14/site-packages/psutil/tests/test_posix.py:369: AssertionError

I backported d6a8a72e35ce1f6cb7e9a14bcd0952881fbab3b1 to get:

__________________________ 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)
E       AssertionError: assert 2 == 1
E        +  where 2 = len([('root', 'pts/0', 2583), ('root', 'sshd', 1007)])
E        +  and   1 = len([('root', 'pts/0', 2583)])

/usr/lib64/python3.14/site-packages/psutil/tests/test_posix.py:383: AssertionError

Notice the root user is listed twice in the output of who -u. Not sure if this is a wrong test expectation or if psutil.users() should report the same.

The CI runs through ansible (I guess over SSH).