code: def _build(
      cmd_flags: str, mock_download_and_prepare: bool = True
  ) -> List[str]:
      """Executes `tfds build {cmd_flags}` and returns the list of generated ds."""
      # Execute the command
      args = main._parse_flags(f"tfds build {cmd_flags}".split())
  
      original_dl_and_prepare = (
          tfds.core.DatasetBuilder.download_and_prepare
      )
  
      # Unfortunately, `mock.Mock` removes `self` from `call_args`, so we have
      # to patch the function to record the generated_ds manually.
      # See:
      # https://stackoverflow.com/questions/64792295/how-to-get-self-instance-in-mock-mock-call-args
      generated_ds_names = []
  
      def _download_and_prepare(self, *args, **kwargs):
          # Remove version from generated name (as only last version can be generated)
          full_name = "/".join(self.info.full_name.split("/")[:-1])
          generated_ds_names.append(full_name)
          if mock_download_and_prepare:
              return
          else:
              return original_dl_and_prepare(self, *args, **kwargs)
  
      with mock.patch(
          "tensorflow_datasets.core.DatasetBuilder.download_and_prepare",
          _download_and_prepare,
      ):
          main.main(args)
      return generated_ds_names
  
imports: import contextlib
  import os
  import pathlib
  from typing import Dict, Iterator, List, Optional
  from unittest import mock
  from absl.testing import parameterized
  from etils import epath
  import pytest
  import tensorflow_datasets
  from tensorflow_datasets import testing
  from tensorflow_datasets.core import download
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.utils import file_utils
  from tensorflow_datasets.scripts.cli import build
  from tensorflow_datasets.scripts.cli import main
label_desc: Use image node_id 3 for calling a global function with example usage: _build(cmd_flags, mock_download_and_prepare) and returns: generated_ds_names, original_dl_and_prepare