diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-01-18 04:04:07 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-18 04:04:07 -0800 |
| commit | ef28caec6c276c76c771c0bad03aea80cd765866 (patch) | |
| tree | cb778d524929e87ee9deb74363ad94610cc04832 /psutil/tests | |
| parent | 2e0952e939d6ab517449314876d8d3488ba5b98b (diff) | |
| download | psutil-ef28caec6c276c76c771c0bad03aea80cd765866.tar.gz | |
Add *new_only* parameter for process_iter() (#1667)
Diffstat (limited to 'psutil/tests')
| -rwxr-xr-x | psutil/tests/test_system.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index e04e120b..f2d07282 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -85,7 +85,7 @@ class TestSystemAPIs(unittest.TestCase): with self.assertRaises(psutil.AccessDenied): list(psutil.process_iter()) - def test_prcess_iter_w_params(self): + def test_prcess_iter_w_attrs(self): for p in psutil.process_iter(attrs=['pid']): self.assertEqual(list(p.info.keys()), ['pid']) with self.assertRaises(ValueError): @@ -105,6 +105,22 @@ class TestSystemAPIs(unittest.TestCase): self.assertGreaterEqual(p.info['pid'], 0) assert m.called + def test_process_iter_new_only(self): + ls1 = list(psutil.process_iter(attrs=['pid'])) + ls2 = list(psutil.process_iter(attrs=['pid'], new_only=True)) + self.assertGreater(len(ls1), len(ls2)) + # assume no more than 3 new processes were created in the meantime + self.assertIn(len(ls2), [0, 1, 2, 3, 4, 5]) + + sproc = get_test_subprocess() + ls = list(psutil.process_iter(attrs=['pid'], new_only=True)) + self.assertIn(len(ls2), [0, 1, 2, 3, 4, 5]) + for p in ls: + if p.pid == sproc.pid: + break + else: + self.fail("subprocess not found") + def test_wait_procs(self): def callback(p): pids.append(p.pid) |
