Skip to content

Commit 86cb186

Browse files
committed
Fix permission error in macOS
1 parent a64cba3 commit 86cb186

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Lib/test/test_profiling/test_sampling_profiler/test_children.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
_cleanup_process,
2020
)
2121

22+
# String to check for in stderr when profiler lacks permissions (e.g., macOS)
23+
_PERMISSION_ERROR_MSG = "Permission Error"
24+
_SKIP_PERMISSION_MSG = "Insufficient permissions for remote profiling"
25+
2226

2327
def _readline_with_timeout(file_obj, timeout):
2428
# Thread-based readline with timeout - works across all platforms
@@ -580,9 +584,12 @@ def test_is_python_process_python_subprocess(self):
580584
while time.time() < deadline:
581585
if proc.poll() is not None:
582586
self.fail(f"Process {proc.pid} exited unexpectedly")
583-
if is_python_process(proc.pid):
584-
detected = True
585-
break
587+
try:
588+
if is_python_process(proc.pid):
589+
detected = True
590+
break
591+
except PermissionError:
592+
self.skipTest(_SKIP_PERMISSION_MSG)
586593
time.sleep(0.05)
587594

588595
self.assertTrue(
@@ -947,6 +954,9 @@ def test_subprocesses_flag_spawns_child_and_creates_output(self):
947954
timeout=SHORT_TIMEOUT,
948955
)
949956

957+
if _PERMISSION_ERROR_MSG in result.stderr:
958+
self.skipTest(_SKIP_PERMISSION_MSG)
959+
950960
# Check that parent output file was created
951961
self.assertTrue(
952962
os.path.exists(output_file),
@@ -1010,6 +1020,9 @@ def test_subprocesses_flag_with_flamegraph_output(self):
10101020
timeout=SHORT_TIMEOUT,
10111021
)
10121022

1023+
if _PERMISSION_ERROR_MSG in result.stderr:
1024+
self.skipTest(_SKIP_PERMISSION_MSG)
1025+
10131026
self.assertTrue(
10141027
os.path.exists(output_file),
10151028
f"Flamegraph output not created. stderr: {result.stderr}",
@@ -1063,6 +1076,9 @@ def test_subprocesses_flag_no_crash_on_quick_child(self):
10631076
timeout=SHORT_TIMEOUT,
10641077
)
10651078

1079+
if _PERMISSION_ERROR_MSG in result.stderr:
1080+
self.skipTest(_SKIP_PERMISSION_MSG)
1081+
10661082
# Should not crash - exit code 0
10671083
self.assertEqual(
10681084
result.returncode,

0 commit comments

Comments
 (0)