def temp_set_var(store):
prev_values = {}<EOL>def set_var(name, value):<EOL><INDENT>if name not in prev_values:  <EOL><INDENT>prev_values[name] = store.get(name)<EOL><DEDENT>if value is None:<EOL><INDENT>try:<EOL><INDENT>del store[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>store[name] = value<EOL><DEDENT><DEDENT>def cleanup():<EOL><INDENT>for n in prev_values:<EOL><INDENT>if prev_values[n] is not None:<EOL><INDENT>store[n] = prev_values[n]<EOL><DEDENT>else:<EOL><INDENT>del store[n]<EOL><DEDENT><DEDENT><DEDENT>return set_var, cleanup<EOL>
Temporary sets a value of a Dict-like object for the duration of a test
:param store: A Dict-like object which holds key-value pairs. The store is
    restored to its original state at the end of the test