-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_order_plugin.py
More file actions
22 lines (17 loc) · 785 Bytes
/
Copy path_order_plugin.py
File metadata and controls
22 lines (17 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Pytest plugin: enforce a deterministic test order from FLAKE_BISECT_ORDER.
The env var holds a newline-separated list of nodeids. Items not in the list are
dropped from the run; items in the list execute in listed order. This makes the
subprocess deterministic regardless of plugins like pytest-randomly that the
target project may have installed.
"""
from __future__ import annotations
import os
def pytest_collection_modifyitems(config, items): # noqa: ARG001
raw = os.environ.get("FLAKE_BISECT_ORDER", "")
if not raw:
return
desired = [line for line in raw.split("\n") if line]
index = {nid: i for i, nid in enumerate(desired)}
kept = [it for it in items if it.nodeid in index]
kept.sort(key=lambda it: index[it.nodeid])
items[:] = kept