@pytest.fixture(scope='function')
def clean_system(request):
 user_config_path = os.path.expanduser('~/.cookiecutterrc')
 user_config_path_backup = os.path.expanduser('~/.cookiecutterrc.backup')
 if os.path.exists(user_config_path):
  user_config_found = True
  shutil.copy(user_config_path, user_config_path_backup)
  os.remove(user_config_path)
 else:
  user_config_found = False
 cookiecutters_dir = os.path.expanduser('~/.cookiecutters')
 cookiecutters_dir_backup = os.path.expanduser('~/.cookiecutters.backup')
 cookiecutters_dir_found = backup_dir(cookiecutters_dir, cookiecutters_dir_backup)
 cookiecutter_replay_dir = os.path.expanduser('~/.cookiecutter_replay')
 cookiecutter_replay_dir_backup = os.path.expanduser('~/.cookiecutter_replay.backup')
 cookiecutter_replay_dir_found = backup_dir(cookiecutter_replay_dir, cookiecutter_replay_dir_backup)
 def restore_backup():
  if (user_config_found and os.path.exists(user_config_path_backup)):
   shutil.copy(user_config_path_backup, user_config_path)
   os.remove(user_config_path_backup)
  restore_backup_dir(cookiecutters_dir, cookiecutters_dir_backup, cookiecutters_dir_found)
  restore_backup_dir(cookiecutter_replay_dir, cookiecutter_replay_dir_backup, cookiecutter_replay_dir_found)
 request.addfinalizer(restore_backup)

@ pytest . fixture ( scope = 'function' ) def clean_system ( request ) : user_config_path = os . path . expanduser ( '~/.cookiecutterrc' ) user_config_path_backup = os . path . expanduser ( '~/.cookiecutterrc.backup' ) if os . path . exists ( user_config_path ) : user_config_found = True shutil . copy ( user_config_path , user_config_path_backup ) os . remove ( user_config_path ) else : user_config_found = False cookiecutters_dir = os . path . expanduser ( '~/.cookiecutters' ) cookiecutters_dir_backup = os . path . expanduser ( '~/.cookiecutters.backup' ) cookiecutters_dir_found = backup_dir ( cookiecutters_dir , cookiecutters_dir_backup ) cookiecutter_replay_dir = os . path . expanduser ( '~/.cookiecutter_replay' ) cookiecutter_replay_dir_backup = os . path . expanduser ( '~/.cookiecutter_replay.backup' ) cookiecutter_replay_dir_found = backup_dir ( cookiecutter_replay_dir , cookiecutter_replay_dir_backup ) def restore_backup ( ) : if ( user_config_found and os . path . exists ( user_config_path_backup ) ) : shutil . copy ( user_config_path_backup , user_config_path ) os . remove ( user_config_path_backup ) restore_backup_dir ( cookiecutters_dir , cookiecutters_dir_backup , cookiecutters_dir_found ) restore_backup_dir ( cookiecutter_replay_dir , cookiecutter_replay_dir_backup , cookiecutter_replay_dir_found ) request . addfinalizer ( restore_backup )
fixture that simulates a clean system with no config/cloned cookiecutters .