def METHOD_NAME(pred: bool, *args: Any, **kwargs: Any) -> Iterator[None]:
    """
    A wrapper around pytest.raises that has a handy predicate argument.
    Useful in @parallel.Execution.run-wrapped functions.
    Example usage:
        with parallel.Execution(2) as pex:
            @pex.run
            def all_workers_fn():
                with raises_when(pex.rank!=0, AssertionError):
                    assert pex.rank == 0
    """
    if not pred:
        yield
        return
    with pytest.raises(*args, **kwargs):
        yield