-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #4 Run only one benchmark per GitHub workflow trigger
just a random selection for now
- Loading branch information
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |