Skip to content

Commit aeca768

Browse files
committed
fixup! Add tests for sampling profiler
1 parent bf9e3fa commit aeca768

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Lib/test/test_sample_profiler.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,24 @@
1111
import unittest
1212
from unittest import mock
1313

14-
import profile.sample
1514
from profile.pstats_collector import PstatsCollector
1615
from profile.stack_collectors import (
1716
CollapsedStackCollector,
1817
)
1918

2019
from test.support.os_helper import unlink
2120

21+
PROCESS_VM_READV_SUPPORTED = False
22+
23+
try:
24+
from _remote_debugging import PROCESS_VM_READV_SUPPORTED
25+
except ImportError:
26+
raise unittest.SkipTest(
27+
"Test only runs when _remote_debugging is available"
28+
)
29+
else:
30+
import profile.sample
31+
2232

2333
class MockFrameInfo:
2434
"""Mock FrameInfo for testing since the real one isn't accessible."""
@@ -256,11 +266,13 @@ def test_pstats_collector_export(self):
256266
self.assertEqual(func1_stats[3], 2.0) # ct (cumulative time)
257267

258268

269+
@unittest.skipIf(
270+
sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED,
271+
"Test only runs on Linux with process_vm_readv support",
272+
)
259273
class TestSampleProfilerIntegration(unittest.TestCase):
260274
@classmethod
261275
def setUpClass(cls):
262-
cls.python_exe = sys.executable
263-
264276
cls.test_script = '''
265277
import time
266278
import os
@@ -472,6 +484,10 @@ def test_sampling_all_threads(self):
472484
# We're not testing output format here
473485

474486

487+
@unittest.skipIf(
488+
sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED,
489+
"Test only runs on Linux with process_vm_readv support",
490+
)
475491
class TestSampleProfilerErrorHandling(unittest.TestCase):
476492
def test_invalid_pid(self):
477493
with self.assertRaises((OSError, RuntimeError)):

0 commit comments

Comments
 (0)