Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pyperformance/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down
21 changes: 20 additions & 1 deletion pyperformance/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Loading