code: def raises_when(
      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
  
file_path: determined/harness/tests/parallel.py
imports: import contextlib
  import itertools
  import sys
  import threading
  import traceback
  from typing import Any, Callable, Dict, Iterator, List, Tuple, TypeVar
  import pytest
  from determined import core
label_desc: Use image node_id 1 for calling a global function with example usage: raises_when(pred) without return types