Skip to content

Commit 37b11d4

Browse files
#3165 fixed Tox failing with --installpkg and multi testenvs (#3186)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fa390ce commit 37b11d4

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

docs/changelog/3165.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed bug where running with --installpkg and multiple envs could not clean up between tests

src/tox/tox_env/python/virtual_env/package/cmd_builder.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import glob
4-
import shutil
54
import tarfile
65
from functools import partial
76
from io import TextIOWrapper
@@ -108,9 +107,8 @@ def extract_install_info(self, for_env: EnvConfigSet, path: Path) -> list[Packag
108107
package: Package = WheelPackage(path, deps)
109108
else: # must be source distribution
110109
work_dir = self.env_tmp_dir / "sdist-extract"
111-
if work_dir.exists(): # pragma: no branch
112-
shutil.rmtree(work_dir) # pragma: no cover
113-
work_dir.mkdir()
110+
if not work_dir.exists(): # pragma: no branch
111+
work_dir.mkdir()
114112
with tarfile.open(str(path), "r:gz") as tar:
115113
tar.extractall(path=str(work_dir)) # noqa: S202
116114
# the register run env is guaranteed to be called before this

tests/tox_env/python/virtual_env/package/test_package_cmd_builder.py

+29
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ def test_tox_install_pkg_wheel(tox_project: ToxProjectCreator, pkg_with_extras_p
3535
assert calls == expected
3636

3737

38+
@pytest.fixture(scope="session")
39+
def pkg_with_sdist(
40+
pkg_with_extras_project: Path,
41+
pkg_builder: Callable[[Path, Path, list[str], bool], Path],
42+
) -> Path:
43+
dist = pkg_with_extras_project / "dist"
44+
pkg_builder(dist, pkg_with_extras_project, ["sdist"], False)
45+
return next(dist.iterdir())
46+
47+
3848
@pytest.fixture()
3949
def pkg_with_extras_project_sdist(
4050
pkg_with_extras_project: Path,
@@ -162,3 +172,22 @@ def test_tox_install_pkg_with_skip_install(
162172
project = tox_project({"tox.ini": ini, "pyproject.toml": (demo_pkg_inline / "pyproject.toml").read_text()})
163173
result = project.run("-e", "py", "--installpkg", str(demo_pkg_inline_wheel))
164174
result.assert_success()
175+
176+
177+
def test_run_installpkg_targz(
178+
tox_project: ToxProjectCreator,
179+
pkg_with_sdist: Path,
180+
enable_pip_pypi_access: str | None, # noqa: ARG001
181+
) -> None:
182+
project = tox_project({
183+
"tox.ini": """
184+
[tox]
185+
envlist = base, flake8
186+
[testenv]
187+
package = sdist
188+
[testenv:base]
189+
[testenv:flake8]
190+
"""
191+
})
192+
outcome = project.run(f"--installpkg={pkg_with_sdist}")
193+
outcome.assert_success()

0 commit comments

Comments
 (0)