Skip to content

Commit

Permalink
Benchmarks: fix inconsistent test collection counters
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Aug 28, 2024
1 parent 482dfc2 commit bc91999
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions qa/benchmarks/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ def pytest_collection_modifyitems(session, config, items):
"""
# Optionally, select a random subset of benchmarks to run.
# based on https://alexwlchan.net/til/2024/run-random-subset-of-tests-in-pytest/
# Note that with current pytest versions the collection/summary stats might be messed up,
# see https://github.com/pytest-dev/pytest/issues/12663
subset_size = config.getoption("--random-subset")
if subset_size >= 0:
_log.info(
f"Selecting random subset of {subset_size} from {len(items)} benchmarks."
)
if subset_size < len(items):
items[:] = random.sample(items, k=subset_size)
selected = random.sample(items, k=subset_size)
selected_ids = set(item.nodeid for item in selected)
deselected = [item for item in items if item.nodeid not in selected_ids]
config.hook.pytest_deselected(items=deselected)
items[:] = selected


def _get_client_credentials_env_var(url: str) -> str:
Expand Down

0 comments on commit bc91999

Please sign in to comment.