Skip to content

Commit

Permalink
#3165 fixed Tox failing with --installpkg and multi testenvs (#3186)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Stefanhg and pre-commit-ci[bot] authored Jan 16, 2024
1 parent fa390ce commit 37b11d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/changelog/3165.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug where running with --installpkg and multiple envs could not clean up between tests
6 changes: 2 additions & 4 deletions src/tox/tox_env/python/virtual_env/package/cmd_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import glob
import shutil
import tarfile
from functools import partial
from io import TextIOWrapper
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

0 comments on commit 37b11d4

Please sign in to comment.