Skip to content

Commit

Permalink
Issue #4 Run only one benchmark per GitHub workflow trigger
Browse files Browse the repository at this point in the history
just a random selection for now
  • Loading branch information
soxofaan committed Jun 19, 2024
1 parent 73c5414 commit de98b93
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/benchmarks.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: "Benchmarks"

# TODO: trigger based on schedule
# TODO: only run subset of benchmarks
on: [push]

jobs:
Expand All @@ -20,4 +19,4 @@ jobs:
- name: Test with pytest
run: |
cd qa/benchmarks
pytest
pytest --random-subset=1
31 changes: 31 additions & 0 deletions qa/benchmarks/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import logging
import random

# TODO: how to make sure the logging/printing from this plugin is actually visible by default?
_log = logging.getLogger(__name__)


def pytest_addoption(parser):
parser.addoption(
"--random-subset",
metavar="N",
action="store",
default=-1,
type=int,
help="Only run random selected subset benchmarks.",
)


def pytest_collection_modifyitems(session, config, items):
"""
Pytest plugin to select a random subset of benchmarks to run.
based on https://alexwlchan.net/til/2024/run-random-subset-of-tests-in-pytest/
"""
subset_size = config.getoption("--random-subset")

if subset_size >= 0:
_log.warning(
f"Selecting random subset of {subset_size} from {len(items)} benchmarks."
)
items[:] = random.sample(items, k=subset_size)

0 comments on commit de98b93

Please sign in to comment.