def METHOD_NAME(
    context_fn: _ContextFactory,
    environment_fn: Optional[_EnvironmentFactory] = None,
):
  context = context_fn()
  with context_stack_impl.context_stack.install(context):
    if environment_fn is not None:
      with contextlib.ExitStack() as stack:
        context_managers = environment_fn()
        for context_manager in context_managers:
          stack.enter_context(context_manager)
        yield
    else:
      yield