From 52a365f8d2b156ab91d2c15e4bc3e1b7746c3875 Mon Sep 17 00:00:00 2001 From: Emma Harper Smith Date: Sat, 31 May 2025 12:30:27 -0700 Subject: [PATCH 1/2] Catch PermissionError when trying to call perf in tests Using Ubuntu 24.04 on the Windows Subsystem for Linux, perf will raise a `PermissionError` instead of `FileNotFoundError`. This commit modifies the tests to catch that. --- Lib/test/test_perf_profiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py index 21d097dbb559ec..0cceb6cf214bda 100644 --- a/Lib/test/test_perf_profiler.py +++ b/Lib/test/test_perf_profiler.py @@ -508,7 +508,7 @@ def _is_perf_version_at_least(major, minor): # a commit hash in the version string, like "6.12.9.g242e6068fd5c" try: output = subprocess.check_output(["perf", "--version"], text=True) - except (subprocess.CalledProcessError, FileNotFoundError): + except (subprocess.CalledProcessError, FileNotFoundError, PermissionError): return False version = output.split()[2] version = version.split("-")[0] From f0eff9318a6e9457c596620b7633cb5311dad0b2 Mon Sep 17 00:00:00 2001 From: Emma Harper Smith Date: Sat, 31 May 2025 17:44:45 -0700 Subject: [PATCH 2/2] Add comment about WSL peculiarity --- Lib/test/test_perf_profiler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py index 0cceb6cf214bda..7529c853f9c152 100644 --- a/Lib/test/test_perf_profiler.py +++ b/Lib/test/test_perf_profiler.py @@ -506,6 +506,9 @@ def _is_perf_version_at_least(major, minor): # The output of perf --version looks like "perf version 6.7-3" but # it can also be perf version "perf version 5.15.143", or even include # a commit hash in the version string, like "6.12.9.g242e6068fd5c" + # + # PermissionError is raised if perf does not exist on the Windows Subsystem + # for Linux, see #134987 try: output = subprocess.check_output(["perf", "--version"], text=True) except (subprocess.CalledProcessError, FileNotFoundError, PermissionError):