]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-121608: Fix test_samply_profiler: only check samply once (#153424)
authorVictor Stinner <vstinner@python.org>
Thu, 9 Jul 2026 19:27:40 +0000 (21:27 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 19:27:40 +0000 (21:27 +0200)
Only run samply_command_works() once. Remove also dead code.

Lib/test/test_samply_profiler.py

index f9ab9207c3c23d8a98d6d1b112cdb812199201f9..6c3be8f38ed0c0003733c7f19b2c2fbdb1c4c6cd 100644 (file)
@@ -31,12 +31,7 @@ if not supports_trampoline_profiling():
     raise unittest.SkipTest("perf trampoline profiling not supported")
 
 
-def samply_command_works():
-    try:
-        cmd = ["samply", "--help"]
-    except (subprocess.SubprocessError, OSError):
-        return False
-
+def _samply_command_works():
     # Check that we can run a simple samply run
     with temp_dir() as script_dir:
         try:
@@ -90,8 +85,10 @@ def run_samply(cwd, *args, **env_vars):
     with gzip.open(output_file, mode="rt", encoding="utf-8") as f:
         return f.read()
 
+SAMPLY_COMMAND_WORKS = _samply_command_works()
+
 
-@unittest.skipUnless(samply_command_works(), "samply command doesn't work")
+@unittest.skipUnless(SAMPLY_COMMAND_WORKS, "samply command doesn't work")
 class TestSamplyProfilerMixin:
     def run_samply(self, script_dir, perf_mode, script):
         raise NotImplementedError()
@@ -145,7 +142,7 @@ class TestSamplyProfilerMixin:
             self.assertNotIn(f"py::baz:{script}", output)
 
 
-@unittest.skipUnless(samply_command_works(), "samply command doesn't work")
+@unittest.skipUnless(SAMPLY_COMMAND_WORKS, "samply command doesn't work")
 class TestSamplyProfiler(unittest.TestCase, TestSamplyProfilerMixin):
     def run_samply(self, script_dir, script, activate_trampoline=True):
         if activate_trampoline:
@@ -240,7 +237,7 @@ class TestSamplyProfiler(unittest.TestCase, TestSamplyProfilerMixin):
                 self.assertIn(line, child_perf_file_contents)
 
 
-@unittest.skipUnless(samply_command_works(), "samply command doesn't work")
+@unittest.skipUnless(SAMPLY_COMMAND_WORKS, "samply command doesn't work")
 class TestSamplyProfilerWithJitDump(unittest.TestCase, TestSamplyProfilerMixin):
     # Regression test for gh-150723: exercises the binary jitdump backend
     # (-Xperf_jit) end to end through samply, unlike TestSamplyProfiler which