class documentation

class twisted.python.monkey.MonkeyPatcher: (source)

View In Hierarchy

Cover up attributes with new objects. Neat for monkey-patching things for unit-testing purposes.

Method __init__ Undocumented
Method addPatch Add a patch so that the attribute name on obj will be assigned to value when patch is called or during runWithPatches.
Method patch Apply all of the patches that have been specified with addPatch. Reverse this operation using restore.
Method restore Restore all original values to any patched objects.
Method runWithPatches Apply each patch already specified. Then run the function f with the given args and kwargs. Restore everything when done.
Instance Variable _patchesToApply Undocumented
Instance Variable _originals Undocumented
Method _alreadyPatched Has the name attribute of obj already been patched by this patcher?
def __init__(self, *patches): (source)

Undocumented

_patchesToApply = (source)

Undocumented

(type: list)
_originals = (source)

Undocumented

(type: list)
def addPatch(self, obj, name, value): (source)

Add a patch so that the attribute name on obj will be assigned to value when patch is called or during runWithPatches.

You can restore the original values with a call to restore().

def _alreadyPatched(self, obj, name): (source)

Has the name attribute of obj already been patched by this patcher?

def patch(self): (source)

Apply all of the patches that have been specified with addPatch. Reverse this operation using restore.

def restore(self): (source)

Restore all original values to any patched objects.

def runWithPatches(self, f, *args, **kw): (source)

Apply each patch already specified. Then run the function f with the given args and kwargs. Restore everything when done.

API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.