From 0cf27856f866a5b9a269fc3a01e3dc902ec4aefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 22 Oct 2024 17:35:13 +0200 Subject: [PATCH] Only use old virtualenv with old tox Fixes https://github.com/fedora-python/tox-current-env/issues/74 --- setup.py | 1 - tests/conftest.py | 5 ++++- tests/utils.py | 8 +++++++- tox.ini | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 5f89a58..00b7c88 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,6 @@ setup( "pytest", "pytest-xdist", "packaging", - "virtualenv<20.22", # pin required for tests with Python 3.6 envs ], }, python_requires=">=3.6", diff --git a/tests/conftest.py b/tests/conftest.py index 2bddad5..9eaebd4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,7 @@ import os import shutil import pytest -from utils import FIXTURES_DIR, TOX4 +from utils import FIXTURES_DIR, TOX4, modify_config, drop_unsupported_pythons @pytest.fixture(autouse=True) @@ -11,6 +11,9 @@ def projdir(tmp_path, monkeypatch, worker_id): pwd.mkdir() for fname in "tox.ini", "setup.py", "pyproject.toml": shutil.copy(FIXTURES_DIR / fname, pwd) + if TOX4: + with modify_config(pwd / "tox.ini") as config: + config["tox"]["envlist"] = drop_unsupported_pythons(config["tox"]["envlist"]) monkeypatch.chdir(pwd) # https://github.com/pypa/pip/issues/5345#issuecomment-386424455 monkeypatch.setenv("XDG_CACHE_HOME", diff --git a/tests/utils.py b/tests/utils.py index fe7fbcf..49727d6 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -83,11 +83,17 @@ def is_available(python): return True +@functools.lru_cache() +def drop_unsupported_pythons(envlist): + return envlist[len("py36,py37,"):] if TOX4 else envlist + + @functools.lru_cache() def envs_from_tox_ini(): cp = ConfigParser() cp.read(FIXTURES_DIR / "tox.ini") - return cp["tox"]["envlist"].split(",") + envlist = drop_unsupported_pythons(cp["tox"]["envlist"]) + return envlist.split(",") def tox_footer(envs=None, spaces=8): diff --git a/tox.ini b/tox.ini index f117266..35a9778 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ extras = tests deps= tox3: tox < 4 + tox3: virtualenv < 20.22 tox4: tox >=4.0.15,< 5 commands = pytest -v {posargs} tests