From 3db98229ac0730e204b832c911861249d389070c Mon Sep 17 00:00:00 2001 From: Marcin Konowalczyk Date: Sat, 27 Apr 2024 15:32:09 +0100 Subject: [PATCH] fix skip with package = wheel (#3269) * patch `pytest --run-integration` to run with dev versions * fix skip with package = wheel * added sdist test * adjust wheel tests * add docs chanelog news fragment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix backticks * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * isinstance(_patch_version, str) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/changelog/3269.feature.rst | 1 + src/tox/tox_env/python/package.py | 7 ++++- tests/session/cmd/test_depends.py | 51 ++++++++++++++++++++++++++++--- tests/test_provision.py | 8 ++++- 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 docs/changelog/3269.feature.rst diff --git a/docs/changelog/3269.feature.rst b/docs/changelog/3269.feature.rst new file mode 100644 index 000000000..8333197ba --- /dev/null +++ b/docs/changelog/3269.feature.rst @@ -0,0 +1 @@ +Fix ``skip_missing_interpreters`` option for ``package = wheel`` diff --git a/src/tox/tox_env/python/package.py b/src/tox/tox_env/python/package.py index ab0035188..f47d6aaac 100644 --- a/src/tox/tox_env/python/package.py +++ b/src/tox/tox_env/python/package.py @@ -120,7 +120,12 @@ def default_wheel_tag(conf: Config, env_name: str | None) -> str: # noqa: ARG00 def child_pkg_envs(self, run_conf: EnvConfigSet) -> Iterator[PackageToxEnv]: if run_conf["package"] == "wheel": - env = self._wheel_build_envs.get(run_conf["wheel_build_env"]) + try: + conf = run_conf["wheel_build_env"] + except Skip: + # the __getitem__ method might raise Skip if the interpreter is not available + return + env = self._wheel_build_envs.get(conf) if env is not None and env.name != self.name: yield env diff --git a/tests/session/cmd/test_depends.py b/tests/session/cmd/test_depends.py index 6e550f50e..a10ace70e 100644 --- a/tests/session/cmd/test_depends.py +++ b/tests/session/cmd/test_depends.py @@ -8,7 +8,7 @@ from tox.pytest import ToxProjectCreator -def test_depends(tox_project: ToxProjectCreator, patch_prev_py: Callable[[bool], tuple[str, str]]) -> None: +def test_depends_wheel(tox_project: ToxProjectCreator, patch_prev_py: Callable[[bool], tuple[str, str]]) -> None: prev_ver, impl = patch_prev_py(True) # has previous python ver = sys.version_info[0:2] py = f"py{''.join(str(i) for i in ver)}" @@ -35,18 +35,61 @@ def test_depends(tox_project: ToxProjectCreator, patch_prev_py: Callable[[bool], py ~ .pkg {py} ~ .pkg {prev_py} ~ .pkg | .pkg-{impl}{prev_ver} - py31 ~ .pkg | ... (could not find python interpreter with spec(s): py31) + py31 ~ .pkg cov2 cov py ~ .pkg {py} ~ .pkg {prev_py} ~ .pkg | .pkg-{impl}{prev_ver} - py31 ~ .pkg | ... (could not find python interpreter with spec(s): py31) + py31 ~ .pkg cov py ~ .pkg {py} ~ .pkg {prev_py} ~ .pkg | .pkg-{impl}{prev_ver} - py31 ~ .pkg | ... (could not find python interpreter with spec(s): py31) + py31 ~ .pkg + """ + assert outcome.out == dedent(expected).lstrip() + + +def test_depends_sdist(tox_project: ToxProjectCreator, patch_prev_py: Callable[[bool], tuple[str, str]]) -> None: + prev_ver, _impl = patch_prev_py(True) # has previous python + ver = sys.version_info[0:2] + py = f"py{''.join(str(i) for i in ver)}" + prev_py = f"py{prev_ver}" + ini = f""" + [tox] + env_list = py,{py},{prev_py},py31,cov2,cov + [testenv] + package = sdist + [testenv:cov] + depends = py,{py},{prev_py},py31 + skip_install = true + [testenv:cov2] + depends = cov + skip_install = true + """ + project = tox_project({"tox.ini": ini, "pyproject.toml": ""}) + outcome = project.run("de") + outcome.assert_success() + + expected = f""" + Execution order: py, {py}, {prev_py}, py31, cov, cov2 + ALL + py ~ .pkg + {py} ~ .pkg + {prev_py} ~ .pkg + py31 ~ .pkg + cov2 + cov + py ~ .pkg + {py} ~ .pkg + {prev_py} ~ .pkg + py31 ~ .pkg + cov + py ~ .pkg + {py} ~ .pkg + {prev_py} ~ .pkg + py31 ~ .pkg """ assert outcome.out == dedent(expected).lstrip() diff --git a/tests/test_provision.py b/tests/test_provision.py index 41eb630e0..2c3d4fcf2 100644 --- a/tests/test_provision.py +++ b/tests/test_provision.py @@ -62,7 +62,13 @@ def _make_tox_wheel( into = tmp_path_factory.mktemp("dist") # pragma: no cover from tox.version import version_tuple # noqa: PLC0415 - version = f"{version_tuple[0]}.{version_tuple[1]}.{int(version_tuple[2]) + 1}" + _patch_version = version_tuple[2] + if isinstance(_patch_version, str) and _patch_version[:3] == "dev": + # Version is in the form of 1.23.dev456, we need to increment the 456 part + version = f"{version_tuple[0]}.{version_tuple[1]}.dev{int(_patch_version[3:]) + 1}" + else: + version = f"{version_tuple[0]}.{version_tuple[1]}.{int(_patch_version) + 1}" + with mock.patch.dict(os.environ, {"SETUPTOOLS_SCM_PRETEND_VERSION": version}): return pkg_builder(into, Path(__file__).parents[1], ["wheel"], False) # pragma: no cover