def test_uninstall_git_package_nspkg_pth_cleanup(mocker, tmp_venv, pool): # this test scenario requires a real installation using the pip installer installer = PipInstaller(tmp_venv, NullIO(), pool) # use a namepspace package package = Package( "namespace-package-one", "1.0.0", source_type="git", source_url="https://github.com/demo/namespace-package-one.git", source_reference="master", ) # we do this here because the virtual env might not be usable if failure case is triggered pth_file_candidate = tmp_venv.site_packages.path / "{}-nspkg.pth".format( package.name) # in order to reproduce the scenario where the git source is removed prior to proper # clean up of nspkg.pth file, we need to make sure the fixture is copied and not # symlinked into the git src directory def copy_only(source, dest): if dest.exists(): dest.unlink() if source.is_dir(): shutil.copytree(str(source), str(dest)) else: shutil.copyfile(str(source), str(dest)) mocker.patch("tests.helpers.copy_or_symlink", new=copy_only) # install package and then remove it installer.install(package) installer.remove(package) assert not Path(pth_file_candidate).exists() # any command in the virtual environment should trigger the error message output = tmp_venv.run("python", "-m", "site") assert "Error processing line 1 of {}".format( pth_file_candidate) not in output
def test_uninstall_git_package_nspkg_pth_cleanup( mocker: MockerFixture, tmp_venv: VirtualEnv, pool: Pool ): # this test scenario requires a real installation using the pip installer installer = PipInstaller(tmp_venv, NullIO(), pool) # use a namepspace package package = Package( "namespace-package-one", "1.0.0", source_type="git", source_url="https://github.com/demo/namespace-package-one.git", source_reference="master", ) # in order to reproduce the scenario where the git source is removed prior to proper # clean up of nspkg.pth file, we need to make sure the fixture is copied and not # symlinked into the git src directory def copy_only(source: Path, dest: Path) -> None: if dest.exists(): dest.unlink() if source.is_dir(): shutil.copytree(str(source), str(dest)) else: shutil.copyfile(str(source), str(dest)) mocker.patch("tests.helpers.copy_or_symlink", new=copy_only) # install package and then remove it installer.install(package) installer.remove(package) pth_file = f"{package.name}-nspkg.pth" assert not tmp_venv.site_packages.exists(pth_file) # any command in the virtual environment should trigger the error message output = tmp_venv.run("python", "-m", "site") assert not re.match(rf"Error processing line 1 of .*{pth_file}", output)