code: def tmp_path(
      request: FixtureRequest, tmp_path_factory: TempPathFactory
  ) -> Generator[Path, None, None]:
      """Return a temporary directory path object which is unique to each test
      function invocation, created as a sub directory of the base temporary
      directory.
  
      By default, a new base temporary directory is created each test session,
      and old bases are removed after 3 sessions, to aid in debugging.
      This behavior can be configured with :confval:`tmp_path_retention_count` and
      :confval:`tmp_path_retention_policy`.
      If ``--basetemp`` is used then it is cleared each session. See :ref:`base
      temporary directory`.
  
      The returned object is a :class:`pathlib.Path` object.
      """
  
      path = _mk_tmp(request, tmp_path_factory)
      yield path
  
      # Remove the tmpdir if the policy is "failed" and the test passed.
      tmp_path_factory: TempPathFactory = request.session.config._tmp_path_factory  # type: ignore
      policy = tmp_path_factory._retention_policy
      result_dict = request.node.stash[tmppath_result_key]
  
      if policy == "failed" and result_dict.get("call", True):
          # We do a "best effort" to remove files, but it might not be possible due to some leaked resource,
          # permissions, etc, in which case we ignore it.
          rmtree(path, ignore_errors=True)
  
      del request.node.stash[tmppath_result_key]
  
imports: import dataclasses
  import os
  import re
  import tempfile
  from pathlib import Path
  from shutil import rmtree
  from typing import Any
  from typing import Dict
  from typing import Generator
  from typing import Optional
  from typing import TYPE_CHECKING
  from typing import Union
  from _pytest.nodes import Item
  from _pytest.reports import CollectReport
  from _pytest.stash import StashKey
  from _pytest.config.argparsing import Parser
  from .pathlib import LOCK_TIMEOUT
  from .pathlib import make_numbered_dir
  from .pathlib import make_numbered_dir_with_cleanup
  from .pathlib import rm_rf
  from .pathlib import cleanup_dead_symlinks
  from _pytest.compat import final, get_user_id
  from _pytest.config import Config
  from _pytest.config import ExitCode
  from _pytest.config import hookimpl
  from _pytest.deprecated import check_ispytest
  from _pytest.fixtures import fixture
  from _pytest.fixtures import FixtureRequest
  from _pytest.monkeypatch import MonkeyPatch
label_desc: Use image node_id 6 for calling a global function with example usage: tmp_path(request, tmp_path_factory) without return types