def patch(self, **kw):
    """Update the environment for the duration of a context."""
    old_environ = self._environ
    self._environ = self._environ.copy()
    self._environ.update(kw)
    yield
    self._environ = old_environ