diff --git a/docs/changelog/3165.bugfix.rst b/docs/changelog/3165.bugfix.rst new file mode 100644 index 000000000..8caad53b9 --- /dev/null +++ b/docs/changelog/3165.bugfix.rst @@ -0,0 +1 @@ +Fixed bug where running with --installpkg and multiple envs could not clean up between tests diff --git a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py index fd38c91b0..a73ebf1a5 100644 --- a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py +++ b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py @@ -1,7 +1,6 @@ from __future__ import annotations import glob -import shutil import tarfile from functools import partial from io import TextIOWrapper @@ -108,9 +107,8 @@ def extract_install_info(self, for_env: EnvConfigSet, path: Path) -> list[Packag package: Package = WheelPackage(path, deps) else: # must be source distribution work_dir = self.env_tmp_dir / "sdist-extract" - if work_dir.exists(): # pragma: no branch - shutil.rmtree(work_dir) # pragma: no cover - work_dir.mkdir() + if not work_dir.exists(): # pragma: no branch + work_dir.mkdir() with tarfile.open(str(path), "r:gz") as tar: tar.extractall(path=str(work_dir)) # noqa: S202 # the register run env is guaranteed to be called before this diff --git a/tests/tox_env/python/virtual_env/package/test_package_cmd_builder.py b/tests/tox_env/python/virtual_env/package/test_package_cmd_builder.py index 5052c6a6b..500e4e237 100644 --- a/tests/tox_env/python/virtual_env/package/test_package_cmd_builder.py +++ b/tests/tox_env/python/virtual_env/package/test_package_cmd_builder.py @@ -35,6 +35,16 @@ def test_tox_install_pkg_wheel(tox_project: ToxProjectCreator, pkg_with_extras_p assert calls == expected +@pytest.fixture(scope="session") +def pkg_with_sdist( + pkg_with_extras_project: Path, + pkg_builder: Callable[[Path, Path, list[str], bool], Path], +) -> Path: + dist = pkg_with_extras_project / "dist" + pkg_builder(dist, pkg_with_extras_project, ["sdist"], False) + return next(dist.iterdir()) + + @pytest.fixture() def pkg_with_extras_project_sdist( pkg_with_extras_project: Path, @@ -162,3 +172,22 @@ def test_tox_install_pkg_with_skip_install( project = tox_project({"tox.ini": ini, "pyproject.toml": (demo_pkg_inline / "pyproject.toml").read_text()}) result = project.run("-e", "py", "--installpkg", str(demo_pkg_inline_wheel)) result.assert_success() + + +def test_run_installpkg_targz( + tox_project: ToxProjectCreator, + pkg_with_sdist: Path, + enable_pip_pypi_access: str | None, # noqa: ARG001 +) -> None: + project = tox_project({ + "tox.ini": """ + [tox] + envlist = base, flake8 + [testenv] + package = sdist + [testenv:base] + [testenv:flake8] + """ + }) + outcome = project.run(f"--installpkg={pkg_with_sdist}") + outcome.assert_success()