@contextlib.contextmanager
def temporary_home_directory():
    # Use the same recipe as in ETSConfig._initialize_application_data
    # to determine the home directory.
    home_var = 'APPDATA' if sys.platform == 'win32' else 'HOME'

    with temporary_directory() as temp_home:
        with restore_mapping_entry(os.environ, home_var):
            os.environ[home_var] = temp_home
            yield
Context manager that temporarily remaps HOME / APPDATA
dataset/ETHPy150Open enthought/traits/traits/etsconfig/tests/test_etsconfig.py/temporary_home_directory