test_interrupt.py: Finish change a1afd91b

Turns out I thought out a1afd91b poorly, I needed to use
a more encompassing try/except block, and replicate the
block in the two tests that do psutil shenanigans.
Signed-off-by: NLucas Meneghel Rodrigues <lookkas@gmail.com>
上级 da4c8478
...@@ -93,18 +93,20 @@ class InterruptTest(unittest.TestCase): ...@@ -93,18 +93,20 @@ class InterruptTest(unittest.TestCase):
old_psutil = True old_psutil = True
for p in process_list: for p in process_list:
p_obj = None
try: try:
p_obj = psutil.Process(p) p_obj = psutil.Process(p)
if p_obj is not None:
if old_psutil:
cmdline_list = psutil.Process(p).cmdline
else:
cmdline_list = psutil.Process(p).cmdline()
if bad_test.path in " ".join(cmdline_list):
bad_test_processes.append(p_obj)
# psutil.NoSuchProcess happens when the original
# process already ended and left the process table
except psutil.NoSuchProcess: except psutil.NoSuchProcess:
pass pass
if p_obj is not None:
if old_psutil:
cmdline_list = psutil.Process(p).cmdline
else:
cmdline_list = psutil.Process(p).cmdline()
if bad_test.path in " ".join(cmdline_list):
bad_test_processes.append(p_obj)
return len(bad_test_processes) == 0 return len(bad_test_processes) == 0
wait.wait_for(wait_until_no_badtest, timeout=2) wait.wait_for(wait_until_no_badtest, timeout=2)
...@@ -146,23 +148,19 @@ class InterruptTest(unittest.TestCase): ...@@ -146,23 +148,19 @@ class InterruptTest(unittest.TestCase):
old_psutil = True old_psutil = True
for p in process_list: for p in process_list:
p_obj = None
try: try:
p_obj = psutil.Process(p) p_obj = psutil.Process(p)
except psutil.NoSuchProcess: if p_obj is not None:
pass
if p_obj is not None:
try:
if old_psutil: if old_psutil:
cmdline_list = psutil.Process(p).cmdline cmdline_list = psutil.Process(p).cmdline
else: else:
cmdline_list = psutil.Process(p).cmdline() cmdline_list = psutil.Process(p).cmdline()
if good_test.path in " ".join(cmdline_list): if good_test.path in " ".join(cmdline_list):
good_test_processes.append(p_obj) good_test_processes.append(p_obj)
# psutil.NoSuchProcess happens when the original # psutil.NoSuchProcess happens when the original
# process already ended and left the process table # process already ended and left the process table
except psutil.NoSuchProcess: except psutil.NoSuchProcess:
pass pass
return len(good_test_processes) == 0 return len(good_test_processes) == 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册