From 543d4a13897616448010c1b7c84c7d5f0eba7c8f Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 6 Nov 2026 14:01:06 -0800 Subject: [PATCH 1/2] Filter benchmarks using the target Python version --- pyperformance/cli.py | 11 ++++++----- pyperformance/tests/test_commands.py | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/pyperformance/cli.py b/pyperformance/cli.py index cac15c33..3628b7a0 100644 --- a/pyperformance/cli.py +++ b/pyperformance/cli.py @@ -317,11 +317,11 @@ def _benchmarks_from_options(options): if not getattr(options, "benchmarks", None): return None manifest = _manifest_from_options(options) - return _select_benchmarks(options.benchmarks, manifest) + return _select_benchmarks(options.benchmarks, manifest, options.python) -def _select_benchmarks(raw, manifest): - from pyperformance import _benchmark_selections +def _select_benchmarks(raw, manifest, python): + from pyperformance import _benchmark_selections, _pythoninfo # Get the raw list of benchmarks. entries = raw.lower() @@ -342,12 +342,13 @@ def parse_entry(o, s): # Get the selections. selected = [] - this_python_version = ".".join(map(str, sys.version_info[:3])) + info = _pythoninfo.get_info(python) + this_python_version = ".".join(map(str, info.sys.version_info[:3])) for bench in _benchmark_selections.iter_selections(manifest, parsed_infos): if isinstance(bench, str): logging.warning(f"no benchmark named {bench!r}") continue - # Filter out any benchmarks that can't be run on the Python version we're running + # Filter using the target interpreter, which may differ from the running Python. if this_python_version in bench.python: selected.append(bench) diff --git a/pyperformance/tests/test_commands.py b/pyperformance/tests/test_commands.py index 5b44f015..80f63979 100644 --- a/pyperformance/tests/test_commands.py +++ b/pyperformance/tests/test_commands.py @@ -1,11 +1,30 @@ import os import os.path import shutil +import sys import textwrap import unittest +from types import SimpleNamespace +from unittest import mock import pyperformance -from pyperformance import tests +from pyperformance import _pythoninfo, cli, tests + + +class BenchmarkSelectionTests(unittest.TestCase): + def test_target_python_version(self): + options = SimpleNamespace( + benchmarks="async_tree_eager", manifest=None, python="target-python" + ) + info = SimpleNamespace(sys=SimpleNamespace(version_info=(3, 16, 0))) + with ( + mock.patch.object(sys, "version_info", (3, 11, 0)), + mock.patch.object(_pythoninfo, "get_info", return_value=info) as get_info, + ): + benchmarks = cli._benchmarks_from_options(options) + + get_info.assert_called_once_with("target-python") + self.assertEqual([bench.name for bench in benchmarks], ["async_tree_eager"]) class FullStackTests(tests.Functional, unittest.TestCase): From 1e8dadf327794ccf4e65431609d5e8ea58336018 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 20 Nov 2026 10:42:50 -0800 Subject: [PATCH 2/2] address pr comments --- doc/changelog.rst | 2 ++ pyperformance/cli.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 5a5f1e19..d72e678f 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,6 +6,8 @@ Version 1.15.0 (unreleased) * Add support for Python 3.15 and drop 3.10 * Bump tornado to 6.6 (fixes ``BufferError`` on PyPy) * Bump genshi to 0.7.12 (fixes ``TypeError`` on Python 3.15) +* Fix benchmark selection checking Python version requirements against the + running interpreter instead of the target specified by ``--python`` Version 1.14.0 (2026-02-07) --------------------------- diff --git a/pyperformance/cli.py b/pyperformance/cli.py index 3628b7a0..cba81b52 100644 --- a/pyperformance/cli.py +++ b/pyperformance/cli.py @@ -185,7 +185,7 @@ def parse_args(): cmd.add_argument("changed_filename", metavar="changed_file.json") # list - cmd = subparsers.add_parser("list", help="List benchmarks of the running Python") + cmd = subparsers.add_parser("list", help="List benchmarks of the target Python") cmds.append(cmd) filter_opts(cmd) @@ -343,13 +343,13 @@ def parse_entry(o, s): # Get the selections. selected = [] info = _pythoninfo.get_info(python) - this_python_version = ".".join(map(str, info.sys.version_info[:3])) + target_python_version = ".".join(map(str, info.sys.version_info[:3])) for bench in _benchmark_selections.iter_selections(manifest, parsed_infos): if isinstance(bench, str): logging.warning(f"no benchmark named {bench!r}") continue # Filter using the target interpreter, which may differ from the running Python. - if this_python_version in bench.python: + if target_python_version in bench.python: selected.append(bench) return selected