def replaceEnvironment(case, myEnv=None):
if myEnv is None:<EOL><INDENT>myEnv = buildEnv()<EOL><DEDENT>oldEnviron = os.environ<EOL>def _cleanup():<EOL><INDENT>os.environ = oldEnviron<EOL><DEDENT>case.addCleanup(_cleanup)<EOL>os.environ = myEnv<EOL>
Replace environment temporarily, restoring it at end of test

    :params myEnv: a dict-like object