Skip to content

Commit a5a8a30

Browse files
committed
gh-152769: Fix test_samply_profiler: only check samply once
Only run samply_command_works() once. Remove also dead code.
1 parent cd9994e commit a5a8a30

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

Lib/test/test_samply_profiler.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ def supports_trampoline_profiling():
3131
raise unittest.SkipTest("perf trampoline profiling not supported")
3232

3333

34-
def samply_command_works():
35-
try:
36-
cmd = ["samply", "--help"]
37-
except (subprocess.SubprocessError, OSError):
38-
return False
39-
34+
def _samply_command_works():
4035
# Check that we can run a simple samply run
4136
with temp_dir() as script_dir:
4237
try:
@@ -90,8 +85,10 @@ def run_samply(cwd, *args, **env_vars):
9085
with gzip.open(output_file, mode="rt", encoding="utf-8") as f:
9186
return f.read()
9287

88+
SAMPLY_COMMAND_WORKS = _samply_command_works()
89+
9390

94-
@unittest.skipUnless(samply_command_works(), "samply command doesn't work")
91+
@unittest.skipUnless(SAMPLY_COMMAND_WORKS, "samply command doesn't work")
9592
class TestSamplyProfilerMixin:
9693
def run_samply(self, script_dir, perf_mode, script):
9794
raise NotImplementedError()
@@ -145,7 +142,7 @@ def baz(n):
145142
self.assertNotIn(f"py::baz:{script}", output)
146143

147144

148-
@unittest.skipUnless(samply_command_works(), "samply command doesn't work")
145+
@unittest.skipUnless(SAMPLY_COMMAND_WORKS, "samply command doesn't work")
149146
class TestSamplyProfiler(unittest.TestCase, TestSamplyProfilerMixin):
150147
def run_samply(self, script_dir, script, activate_trampoline=True):
151148
if activate_trampoline:
@@ -240,7 +237,7 @@ def compile_trampolines_for_all_functions():
240237
self.assertIn(line, child_perf_file_contents)
241238

242239

243-
@unittest.skipUnless(samply_command_works(), "samply command doesn't work")
240+
@unittest.skipUnless(SAMPLY_COMMAND_WORKS, "samply command doesn't work")
244241
class TestSamplyProfilerWithJitDump(unittest.TestCase, TestSamplyProfilerMixin):
245242
# Regression test for gh-150723: exercises the binary jitdump backend
246243
# (-Xperf_jit) end to end through samply, unlike TestSamplyProfiler which

0 commit comments

Comments
 (0)