def CallCountsToMockFunctions(mock_function):
  """A decorator that passes a call count to the function it decorates.

  Examples:
    @CallCountsToMockFunctions
    def foo(call_count):
      return call_count
    ...
    ...
    [foo(), foo(), foo()]
    [0, 1, 2]
  """

  counter = [0]

  def Result(*args, **kwargs):
    # For some values of `counter`, the mock function would simulate raising
    # an exception, so let the test case catch the exception via
    # `unittest.TestCase.assertRaises()` and to also handle recursive functions.
    prev_counter = counter[0]
    counter[0] += 1

    ret_value = mock_function(prev_counter, *args, **kwargs)

    return ret_value

  return Result