import shutil


def backup_install_dir(install_dir, tmp_path_factory):
    """Backup the install dir such that it can be restored for each test
    function without having to reinstall from scratch.
    """
    backup_root = tmp_path_factory.mktemp("repobee_test_backups")
    repobee_install_backup = backup_root / "repobee_install_backup"
    shutil.copytree(install_dir, repobee_install_backup)
    return repobee_install_backup