giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.37k forks source link

[SunOS] `saved=None` confuses `TestFetchAllProcesses.test_all` #2358

Open mtelka opened 5 months ago

mtelka commented 5 months ago

Summary

Description

Both Process.uids() and Process.gids() can return saved = None, but this makes the TestFetchAllProcesses.test_all test to fail with errors like:

________________________ TestFetchAllProcesses.test_all ________________________

self = <psutil.tests.test_process_all.TestFetchAllProcesses testMethod=test_all>

    def test_all(self):
        failures = []
        for info in self.iter_proc_info():
            for name, value in info.items():
                meth = getattr(self, name)
                try:
                    meth(value, info)
                except Exception:  # noqa: BLE001
                    s = '\n' + '=' * 70 + '\n'
                    s += "FAIL: name=test_%s, pid=%s, ret=%s\ninfo=%s\n" % (
                        name,
                        info['pid'],
                        repr(value),
                        info,
                    )
                    s += '-' * 70
                    s += "\n%s" % traceback.format_exc()
                    s = "\n".join((" " * 4) + i for i in s.splitlines()) + "\n"
                    failures.append(s)
                else:
                    if value not in (0, 0.0, [], None, '', {}):
                        assert value, value
        if failures:
>           raise self.fail(''.join(failures))
E           AssertionError:
E               ======================================================================
E               FAIL: name=test_gids, pid=0, ret=puids(real=0, effective=0, saved=None)
E               info={'pid': 0, 'exe': '', 'num_threads': 1, 'memory_full_info': pmem(rss=0, vms=0), 'gids': puids(real=0, effective=0, saved=None), 'cpu_num': 1, 'name': 'sched', 'create_time': 1705580724.5222604, 'memory_info': pmem(rss=0, vms=0), 'username': 'root', 'nice': 0, 'uids': puids(real=0, effective=0, saved=None), 'num_ctx_switches': pctxsw(voluntary=477, involuntary=71), 'ppid': 0, 'status': 'stopped', 'cmdline': ['sched']}
E               ----------------------------------------------------------------------
E               Traceback (most recent call last):
E                 File "/usr/lib/python3.9/vendor-packages/psutil/tests/test_process_all.py", line 135, in test_all
E                   meth(value, info)
E                 File "/usr/lib/python3.9/vendor-packages/psutil/tests/test_process_all.py", line 223, in gids
E                   self.assertIsInstance(gid, int)
E                 File "/usr/lib/python3.9/unittest/case.py", line 1260, in assertIsInstance
E                   self.fail(self._formatMessage(msg, standardMsg))
E                 File "/usr/lib/python3.9/unittest/case.py", line 676, in fail
E                   raise self.failureException(msg)
E               AssertionError: None is not an instance of <class 'int'>
E
E               ======================================================================
E               FAIL: name=test_uids, pid=0, ret=puids(real=0, effective=0, saved=None)
E               info={'pid': 0, 'exe': '', 'num_threads': 1, 'memory_full_info': pmem(rss=0, vms=0), 'gids': puids(real=0, effective=0, saved=None), 'cpu_num': 1, 'name': 'sched', 'create_time': 1705580724.5222604, 'memory_info': pmem(rss=0, vms=0), 'username': 'root', 'nice': 0, 'uids': puids(real=0, effective=0, saved=None), 'num_ctx_switches': pctxsw(voluntary=477, involuntary=71), 'ppid': 0, 'status': 'stopped', 'cmdline': ['sched']}
E               ----------------------------------------------------------------------
E               Traceback (most recent call last):
E                 File "/usr/lib/python3.9/vendor-packages/psutil/tests/test_process_all.py", line 135, in test_all
E                   meth(value, info)
E                 File "/usr/lib/python3.9/vendor-packages/psutil/tests/test_process_all.py", line 215, in uids
E                   self.assertIsInstance(uid, int)
E                 File "/usr/lib/python3.9/unittest/case.py", line 1260, in assertIsInstance
E                   self.fail(self._formatMessage(msg, standardMsg))
E                 File "/usr/lib/python3.9/unittest/case.py", line 676, in fail
E                   raise self.failureException(msg)
E               AssertionError: None is not an instance of <class 'int'>

...