code: def on_rm_rf_error(func, path, exc, **kwargs):
      """Handles known read-only errors during rmtree.
  
      The returned value is used only by our own tests.
      """
      start_path = kwargs["start_path"]
      exctype, excvalue = exc[:2]
  
      # another process removed the file in the middle of the "rm_rf" (xdist for example)
      # more context: https://github.com/pytest-dev/pytest/issues/5974#issuecomment-543799018
      if (
          isinstance(excvalue, OSError)
          and excvalue.errno == errno.ENOENT
      ):
          return False
  
      if not isinstance(excvalue, OSError) or excvalue.errno not in (
          errno.EACCES,
          errno.EPERM,
      ):
          warnings.warn(
              PytestWarning(
                  "(rm_rf) error removing {}\n{}: {}".format(
                      path, exctype, excvalue
                  )
              )
          )
          return False
  
      if func not in (os.rmdir, os.remove, os.unlink):
          warnings.warn(
              PytestWarning(
                  "(rm_rf) unknown function {} when removing {}:\n{}: {}".format(
                      path, func, exctype, excvalue
                  )
              )
          )
          return False
  
      # Chmod + retry.
      import stat
  
      def chmod_rw(p):
          mode = os.stat(p).st_mode
          os.chmod(p, mode | stat.S_IRUSR | stat.S_IWUSR)
  
      # For files, we need to recursively go upwards in the directories to
      # ensure they all are also writable.
      p = Path(path)
      if p.is_file():
          for parent in p.parents:
              chmod_rw(str(parent))
              # stop when we reach the original path passed to rm_rf
              if parent == start_path:
                  break
      chmod_rw(str(path))
  
      func(path)
      return True
  
imports: from __future__ import absolute_import
  import atexit
  import errno
  import fnmatch
  import itertools
  import operator
  import os
  import shutil
  import sys
  import uuid
  import warnings
  from functools import partial
  from functools import reduce
  from os.path import expanduser
  from os.path import expandvars
  from os.path import isabs
  from os.path import sep
  from posixpath import sep
  import six
  from six.moves import map
  from .compat import PY36
  from _pytest.warning_types import PytestWarning
label_desc: Use image node_id 2 for calling a global function with example usage: on_rm_rf_error(func, path, exc) and returns: True, False, False, False