diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index fe9b2fcc7..aaced046e 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -964,17 +964,41 @@ def assertProcessZombie(self, proc): self.assertEqual(proc.status(), psutil.STATUS_ZOMBIE) # It should be considered 'running'. assert proc.is_running() + assert psutil.pid_exists(proc.pid) # as_dict() shouldn't crash. proc.as_dict() # It should show up in pids() and process_iter(). self.assertIn(proc.pid, psutil.pids()) self.assertIn(proc.pid, [x.pid for x in psutil.process_iter()]) - # It cannot be signaled or terminated. + psutil._pmap = {} + self.assertIn(proc.pid, [x.pid for x in psutil.process_iter()]) + # Call all methods. + ns = process_namespace(proc) + for fun, name in ns.iter(ns.all): + with self.subTest(name): + try: + fun() + except (psutil.ZombieProcess, psutil.AccessDenied): + pass + # Make sure getters does not return 'null' values. + for fun, name in ns.iter(ns.getters): + with self.subTest(name): + try: + retval = fun() + self.assertNotIn(retval, ("", None, [])) + except (psutil.ZombieProcess, psutil.AccessDenied): + pass + # Zombie cannot be signaled or terminated. proc.suspend() proc.resume() proc.terminate() proc.kill() assert proc.is_running() + assert psutil.pid_exists(proc.pid) + self.assertIn(proc.pid, psutil.pids()) + self.assertIn(proc.pid, [x.pid for x in psutil.process_iter()]) + psutil._pmap = {} + self.assertIn(proc.pid, [x.pid for x in psutil.process_iter()]) # Its parent should 'see' it (edit: not true on BSD and MACOS). # descendants = [x.pid for x in psutil.Process().children( diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 5cc1f9291..3ab05ba0c 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -1322,27 +1322,6 @@ def assert_raises_nsp(fun, fun_name): def test_zombie_process(self): parent, zombie = self.spawn_zombie() self.assertProcessZombie(zombie) - ns = process_namespace(zombie) - for fun, name in ns.iter(ns.all): - with self.subTest(name): - try: - fun() - except (psutil.ZombieProcess, psutil.AccessDenied): - pass - - for fun, name in ns.iter(ns.getters): - with self.subTest(name): - try: - retval = fun() - self.assertNotIn(retval, ("", None, [])) - except (psutil.ZombieProcess, psutil.AccessDenied): - pass - - assert psutil.pid_exists(zombie.pid) - self.assertIn(zombie.pid, psutil.pids()) - self.assertIn(zombie.pid, [x.pid for x in psutil.process_iter()]) - psutil._pmap = {} - self.assertIn(zombie.pid, [x.pid for x in psutil.process_iter()]) @unittest.skipIf(not POSIX, 'POSIX only') def test_zombie_process_is_running_w_exc(self):