def get_group(
    items: Iterable[nodes.Node], group_count: int, group_id: int
) -> Sequence[nodes.Node]:
    """Get the items from the passed in group based on group count."""
    if not (0 <= group_id < group_count):
        raise ValueError("Invalid test-group argument")

    def get_group_id(node: nodes.Node) -> int:
        # use the file path instead of node id, so all tests in a file run together.
        path_bytes = str(node.path).encode()
        digest_bytes = hashlib.sha256(path_bytes).digest()
        digest = int.from_bytes(digest_bytes, "little")
        return digest % group_count

    return [item for item in items if get_group_id(item) == group_id]
Get the items from the passed in group based on group count.
conftest.py