@pytest.fixture(scope='function')
def back_up_rc(request, user_config_path):
 user_config_path_backup = os.path.expanduser('~/.cookiecutterrc.backup')
 if os.path.exists(user_config_path):
  shutil.copy(user_config_path, user_config_path_backup)
  os.remove(user_config_path)
 def remove_test_rc():
  '\n        Remove the ~/.cookiecutterrc that has been created in the test.\n        '
  if os.path.exists(user_config_path):
   os.remove(user_config_path)
 def restore_original_rc():
  '\n        If it existed, restore the original ~/.cookiecutterrc\n        '
  if os.path.exists(user_config_path_backup):
   shutil.copy(user_config_path_backup, user_config_path)
   os.remove(user_config_path_backup)
 request.addfinalizer(restore_original_rc)
 request.addfinalizer(remove_test_rc)

@ pytest . fixture ( scope = 'function' ) def back_up_rc ( request , user_config_path ) : user_config_path_backup = os . path . expanduser ( '~/.cookiecutterrc.backup' ) if os . path . exists ( user_config_path ) : shutil . copy ( user_config_path , user_config_path_backup ) os . remove ( user_config_path ) def remove_test_rc ( ) : if os . path . exists ( user_config_path ) : os . remove ( user_config_path ) def restore_original_rc ( ) : if os . path . exists ( user_config_path_backup ) : shutil . copy ( user_config_path_backup , user_config_path ) os . remove ( user_config_path_backup ) request . addfinalizer ( restore_original_rc ) request . addfinalizer ( remove_test_rc )
back up an existing cookiecutter rc and restore it after the test .