code: def cached_dataset(f, url=None, version=None, paths=None):
      """Test decorator providing a clone of `url` from cache
  
      If config datalad.tests.cache is not set, delivers a clone in a temporary
      location of the original `url`. Otherwise that clone is in fact a clone of a
      cached dataset (origin being the cache instead of `url`).
      This allows to reduce time and network traffic when using a dataset in
      different tests.
  
      The clone will checkout `version` and get the content for `paths`.
  
      Parameters
      ----------
      url: str
          URL to the to be cloned dataset
      version: str
          committish to checkout in the clone
      paths: str or list
          annexed content to get
  
      Returns
      -------
      Dataset
          a clone of the dataset at `url` at a temporary location (cleaned up,
          after decorated test is finished - see with_tempfile). If caching is
          enabled, it's actually a clone of a clone, 'origin' being the clone in
          cache rather than the original repo at `url`.
      """
  
      @better_wraps(f)
      @with_tempfile
      def _wrap_cached_dataset(*arg, **kw):
          if DATALAD_TESTS_CACHE:
              # Note: We can't pass keys based on `paths` parameter to
              # get_cached_dataset yet, since translation to keys depends on a
              # worktree. We'll have the worktree of `version` only after cloning.
              ds = get_cached_dataset(url, version=version)
              clone_ds = Clone()(ds.pathobj, arg[-1])
          else:
              clone_ds = Clone()(url, arg[-1])
          # save some cycles
          clone_repo = clone_ds.repo
          if version:
              clone_repo.checkout(version)
          if paths and AnnexRepo.is_valid_repo(clone_ds.path):
              # just assume ds is annex as well. Otherwise `Clone` wouldn't
              # work correctly - we don't need to test its implementation here
              if DATALAD_TESTS_CACHE:
                  # cache is enabled; we need to make sure it has the desired
                  # content, so clone_ds can get it from there. However, we got
                  # `paths` and potentially a `version` they refer to. We can't
                  # assume the same (or any) worktree in cache. Hence we need to
                  # translate to keys.
                  # MIH Despite the variable names used in this function
                  # (pathS, keyS) they ultimately are passed to get(..., key=True)
                  # which means that it can ever only be a single path and a
                  # single key -- this is very confusing.
                  # the key determination could hence be done with
                  # get_file_annexinfo() in a much simpler way, but it seems this
                  # function wants to be ready for more, sigh
                  keys = [
                      p["key"]
                      for p in clone_repo.get_content_annexinfo(
                          ensure_list(paths), init=None
                      ).values()
                      if "key" in p
                  ]
                  if keys:
                      ds.repo.get(keys, key=True)
                  clone_repo.fsck(remote=DEFAULT_REMOTE, fast=True)
  
              clone_ds.get(paths)
          return f(*(arg[:-1] + (clone_ds,)), **kw)
  
      return _wrap_cached_dataset
  
file_path: datalad/datalad/tests/utils_cached_dataset.py
imports: from datalad import cfg
  from datalad.core.distributed.clone import Clone
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.tests.utils_pytest import DEFAULT_REMOTE, with_tempfile
  from datalad.utils import Path, better_wraps, ensure_list, optional_args, rmtree
label_desc: Use image node_id 3 for calling a global function with example usage: cached_dataset(f, url, version, paths) and returns: _wrap_cached_dataset, f