Skip to content

Commit

Permalink
print multiple failures
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed May 2, 2020
1 parent 06687fa commit 3000e63
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions psutil/tests/test_contracts.py
Expand Up @@ -10,10 +10,11 @@
"""

import errno
import multiprocessing
import os
import stat
import time
import multiprocessing
import traceback

from psutil import AIX
from psutil import BSD
Expand Down Expand Up @@ -336,7 +337,8 @@ def proc_info(pid):
info['rlimit'] = p.rlimit(psutil.RLIMIT_NOFILE)
except psutil.AccessDenied:
pass
except psutil.NoSuchProcess:
except psutil.NoSuchProcess as err:
assert err.pid == pid
return {}
else:
for k, v in info.copy().items():
Expand Down Expand Up @@ -364,10 +366,26 @@ def test_all(self):
# same object as test_contracts.proc_info".
from psutil.tests.test_contracts import proc_info

failures = []
for info in self.pool.imap_unordered(proc_info, psutil.pids()):
for name, value in info.items():
meth = getattr(self, name)
meth(value, info)
try:
meth(value, info)
except AssertionError:
s = '\n' + '=' * 70 + '\n'
s += "FAIL: test_%s pid=%s, ret=%s\n" % (
name, info['pid'], repr(value))
s += '-' * 70
s += "\n%s" % traceback.format_exc()
s = "\n".join((" " * 4) + i for i in s.splitlines())
s += '\n'
failures.append(s)
else:
if value not in (0, 0.0, [], None, '', {}):
assert value, value
if failures:
raise self.fail(''.join(failures))

def cmdline(self, ret, info):
self.assertIsInstance(ret, list)
Expand Down

0 comments on commit 3000e63

Please sign in to comment.