Get the items from the passed in group based on group count.
(
items: Iterable[nodes.Node], group_count: int, group_id: int
)
| 38 | |
| 39 | |
| 40 | def get_group( |
| 41 | items: Iterable[nodes.Node], group_count: int, group_id: int |
| 42 | ) -> Sequence[nodes.Node]: |
| 43 | """Get the items from the passed in group based on group count.""" |
| 44 | if not (0 <= group_id < group_count): |
| 45 | raise ValueError("Invalid test-group argument") |
| 46 | |
| 47 | def get_group_id(node: nodes.Node) -> int: |
| 48 | # use the file path instead of node id, so all tests in a file run together. |
| 49 | path_bytes = str(node.path).encode() |
| 50 | digest_bytes = hashlib.sha256(path_bytes).digest() |
| 51 | digest = int.from_bytes(digest_bytes, "little") |
| 52 | return digest % group_count |
| 53 | |
| 54 | return [item for item in items if get_group_id(item) == group_id] |
| 55 | |
| 56 | |
| 57 | def pytest_addoption(parser): |
no test coverage detected