summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-05-03 18:26:48 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2020-05-03 18:26:48 +0200
commit0354586e3caacc950cfc01b02099e7a283654bf9 (patch)
treeeaa4af68ab97e53394f29492c26f87546aa97840
parent336d20709f5a0524e673e1a72f4f5e282fd259b4 (diff)
downloadpsutil-0354586e3caacc950cfc01b02099e7a283654bf9.tar.gz
clear the cache of a Process instance before each fun call
-rw-r--r--psutil/tests/__init__.py5
-rwxr-xr-xpsutil/tests/test_contracts.py6
2 files changed, 5 insertions, 6 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index 986df572..2da0bc76 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -1074,14 +1074,15 @@ class process_namespace:
def __init__(self, proc):
self._proc = proc
- def iter(self, *tuples):
+ def iter(self, *tuples, clear_cache=True):
"""Given a list of tuples yields a set of (fun, fun_name) tuples
in random order.
"""
ls = list(tuples)
random.shuffle(ls)
for fun_name, args, kwds in ls:
- self.clear_cache()
+ if clear_cache:
+ self.clear_cache()
fun = getattr(self._proc, fun_name)
fun = functools.partial(fun, *args, **kwds)
yield (fun, fun_name)
diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py
index 8f4a90a7..264a5c4b 100755
--- a/psutil/tests/test_contracts.py
+++ b/psutil/tests/test_contracts.py
@@ -10,7 +10,6 @@ Some of these are duplicates of tests test_system.py and test_process.py
"""
import errno
-import functools
import multiprocessing
import os
import signal
@@ -361,10 +360,9 @@ def proc_info(pid):
name, ppid = d['name'], d['ppid']
info = {'pid': proc.pid}
+ ns = process_namespace(proc)
with proc.oneshot():
- for fun_name, args, kwds in process_namespace.getters:
- fun = getattr(proc, fun_name)
- fun = functools.partial(fun, *args, **kwds)
+ for fun, fun_name in ns.iter(*ns.getters, clear_cache=False):
try:
info[fun_name] = fun()
except psutil.NoSuchProcess as exc: