Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bc91999

Browse files
committedAug 28, 2024·
Benchmarks: fix inconsistent test collection counters
Also see pytest-dev/pytest#12663
1 parent 482dfc2 commit bc91999

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎qa/benchmarks/tests/conftest.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ def pytest_collection_modifyitems(session, config, items):
5858
"""
5959
# Optionally, select a random subset of benchmarks to run.
6060
# based on https://alexwlchan.net/til/2024/run-random-subset-of-tests-in-pytest/
61-
# Note that with current pytest versions the collection/summary stats might be messed up,
62-
# see https://github.com/pytest-dev/pytest/issues/12663
6361
subset_size = config.getoption("--random-subset")
6462
if subset_size >= 0:
6563
_log.info(
6664
f"Selecting random subset of {subset_size} from {len(items)} benchmarks."
6765
)
6866
if subset_size < len(items):
69-
items[:] = random.sample(items, k=subset_size)
67+
selected = random.sample(items, k=subset_size)
68+
selected_ids = set(item.nodeid for item in selected)
69+
deselected = [item for item in items if item.nodeid not in selected_ids]
70+
config.hook.pytest_deselected(items=deselected)
71+
items[:] = selected
7072

7173

7274
def _get_client_credentials_env_var(url: str) -> str:

0 commit comments

Comments
 (0)
Please sign in to comment.