def monkeypatch(klass, methodname=None):
 def decorator(func):
  try:
   name = (methodname or func.__name__)
  except AttributeError:
   raise AttributeError(('%s has no __name__ attribute: you should provide an explicit `methodname`' % func))
  setattr(klass, name, func)
  return func
 return decorator

def monkeypatch ( klass , methodname = None ) : def decorator ( func ) : try : name = ( methodname or func . __name__ ) except AttributeError : raise AttributeError ( ( '%s has no __name__ attribute: you should provide an explicit `methodname`' % func ) ) setattr ( klass , name , func ) return func return decorator
the returned monkeypatch fixture provides these helper methods to modify objects .