def undo(self):
for obj, name, value in reversed(self._setattr):<EOL><INDENT>if value is not notset:<EOL><INDENT>setattr(obj, name, value)<EOL><DEDENT>else:<EOL><INDENT>delattr(obj, name)<EOL><DEDENT><DEDENT>self._setattr[:] = []<EOL>for dictionary, name, value in reversed(self._setitem):<EOL><INDENT>if value is notset:<EOL><INDENT>try:<EOL><INDENT>del dictionary[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass  <EOL><DEDENT><DEDENT>else:<EOL><INDENT>dictionary[name] = value<EOL><DEDENT><DEDENT>self._setitem[:] = []<EOL>if self._savesyspath is not None:<EOL><INDENT>sys.path[:] = self._savesyspath<EOL>self._savesyspath = None<EOL><DEDENT>if self._cwd is not None:<EOL><INDENT>os.chdir(self._cwd)<EOL>self._cwd = None<EOL><DEDENT>
Undo previous changes.  This call consumes the
        undo stack. Calling it a second time has no effect unless
        you do more monkeypatching after the undo call.

        There is generally no need to call `undo()`, since it is
        called automatically during tear-down.

        Note that the same `monkeypatch` fixture is used across a
        single test function invocation. If `monkeypatch` is used both by
        the test function itself and one of the test fixtures,
        calling `undo()` will undo all of the changes made in
        both functions.