def test_reset_environment(self): """Test resetting environment.""" environment.set_value('ASAN_OPTIONS', 'saved_options') untrusted_env.reset_environment() environment.set_value('ASAN_OPTIONS', 'replaced') untrusted_env.reset_environment() runner = remote_process_host.RemoteProcessRunner('/bin/sh', ['-c']) result = runner.run_and_wait(['echo $ASAN_OPTIONS']) self.assertEqual(result.output, 'saved_options\n')
def reset_environment(): """Resets environment variables to their initial state. Saves the initial state on first call.""" global _initial_environment if _initial_environment is None: _initial_environment = copy() # There is nothing to reset if we are initializing for the first time. else: # Clean current environment. os.environ.clear() # Add shared variables with values from _initial_environment. os.environ.update(_initial_environment) if is_trusted_host(): from bot.untrusted_runner import environment as untrusted_env untrusted_env.reset_environment()