aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinghao Li <minghaoli@google.com>2024-05-12 23:31:04 -0700
committerGitHub <noreply@github.com>2024-05-12 23:31:04 -0700
commitbb5e4444a649853b8c7fd390e6ca9be41be0d1bd (patch)
tree03800d815b64da5867325ce7c1f915c99b2043d7
parent07f0a24e8d1b6d568d8e7d26eea28f0608c49322 (diff)
downloadmobly-upstream-master.tar.gz
Fix utils.stop_standing_subprocess error on Mac OS (#920)upstream-master
-rw-r--r--mobly/utils.py7
-rwxr-xr-xtests/mobly/utils_test.py6
2 files changed, 7 insertions, 6 deletions
diff --git a/mobly/utils.py b/mobly/utils.py
index 66f0b50..4eee19f 100644
--- a/mobly/utils.py
+++ b/mobly/utils.py
@@ -277,12 +277,9 @@ def _collect_process_tree(starting_pid):
ps_results = (
subprocess.check_output(
[
- 'ps',
- '-o',
- 'pid',
- '--ppid',
+ 'pgrep',
+ '-P',
str(pid),
- '--noheaders',
]
)
.decode()
diff --git a/tests/mobly/utils_test.py b/tests/mobly/utils_test.py
index 11852c1..e3a0fe4 100755
--- a/tests/mobly/utils_test.py
+++ b/tests/mobly/utils_test.py
@@ -157,7 +157,11 @@ class UtilsTest(unittest.TestCase):
pid_list = utils._collect_process_tree(777)
- self.assertListEqual(pid_list, [780, 791, 799, 888, 890, 913, 999])
+ expected_child_pid_list = [780, 791, 799, 888, 890, 913, 999]
+ self.assertListEqual(pid_list, expected_child_pid_list)
+
+ for pid in [777] + expected_child_pid_list:
+ mock_check_output.assert_any_call(['pgrep', '-P', str(pid)])
@mock.patch.object(os, 'kill')
@mock.patch.object(utils, '_collect_process_tree')