Skip to content

Commit

Permalink
refact assertProcessGone
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Oct 1, 2023
1 parent 77e5b74 commit a5c8428
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,13 +975,16 @@ def assertProcessGone(self, proc):
ns = process_namespace(proc)
for fun, name in ns.iter(ns.all, clear_cache=True):
with self.subTest(proc=proc, name=name):
with self.assertRaises(psutil.NoSuchProcess) as cm:
try:
fun()
except psutil.ZombieProcess:
raise AssertionError(
"wasn't supposed to raise ZombieProcess")
self._check_proc_exc(proc, cm.exception)
try:
ret = fun()
except psutil.ZombieProcess:
raise
except psutil.NoSuchProcess as exc:
self._check_proc_exc(proc, exc)
else:
msg = "Process.%s() didn't raise NSP and returned %r" % (
name, ret)
raise AssertionError(msg)
proc.wait(timeout=0) # assert not raise TimeoutExpired

def assertProcessZombie(self, proc):
Expand Down

0 comments on commit a5c8428

Please sign in to comment.