code: def patch_module(name, pname, pfile=None, attrib=None):
      
  
      if attrib is None:
          attrib = {}
      spec = importlib.util.find_spec(name)
      spec.name = pname
      if pfile is not None:
          spec.origin = pfile
      spec.loader.name = pname
      mod = importlib.util.module_from_spec(spec)
      mod.__spec__ = spec
      mod.__loader__ = spec.loader
      sys.modules[pname] = mod
      spec.loader.exec_module(mod)
      for k, v in attrib.items():
          setattr(mod, k, v)
      return mod
docs: Create a patched copy of the named module and register it in
      ``sys.modules``.
  
      Parameters
      ----------
      name : string
        Name of source module
      pname : string
        Name of patched copy of module
      pfile : string or None, optional (default None)
        Value to assign as source file name of patched module
      attrib : dict or None, optional (default None)
        Dict of attribute names and values to assign to patched module
  
      Returns
      -------
      mod : module
        Patched module