code: def _patch_unwrap_mock_aware():
      """
      contextmanager which replaces ``inspect.unwrap`` with a version
      that's aware of mock objects and doesn't recurse on them
      """
      real_unwrap = getattr(inspect, "unwrap", None)
      if real_unwrap is None:
          yield
      else:
  
          def _mock_aware_unwrap(obj, stop=None):
              try:
                  if stop is None or stop is _is_mocked:
                      return real_unwrap(obj, stop=_is_mocked)
                  return real_unwrap(
                      obj, stop=lambda obj: _is_mocked(obj) or stop(obj)
                  )
              except Exception as e:
                  warnings.warn(
                      "Got %r when unwrapping %r.  This is usually caused "
                      "by a violation of Python's object protocol; see e.g. "
                      "https://github.com/pytest-dev/pytest/issues/5080"
                      % (e, obj),
                      PytestWarning,
                  )
                  raise
  
          inspect.unwrap = _mock_aware_unwrap
          try:
              yield
          finally:
              inspect.unwrap = real_unwrap
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import inspect
  import platform
  import sys
  import traceback
  import warnings
  from contextlib import contextmanager
  import pytest
  from _pytest._code.code import ExceptionInfo
  from _pytest._code.code import ReprFileLocation
  from _pytest._code.code import TerminalRepr
  from _pytest.compat import safe_getattr
  from _pytest.fixtures import FixtureRequest
  from _pytest.outcomes import Skipped
  from _pytest.warning_types import PytestWarning
label_desc: Use image node_id 12 for calling a global function with example usage: _patch_unwrap_mock_aware() and returns: real_unwrap, real_unwrap