Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3165 fixed Tox failing with --installpkg and multi testenvs #3186

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()