Skip to content

Commit 869b569

Browse files
committed
Tests: Don't assume Python 3.10 is always installed, use current Python version
See #3089 (review) test_allowed_implicit_cli_envs[py310] assumed Python 3.10 is installed. It failed without it: ____________________ test_allowed_implicit_cli_envs[py310] _____________________ [gw3] linux -- Python 3.12.0 /usr/bin/python3 env_name = 'py310' tox_project = <function init_fixture.<locals>._init at 0x7febd4e1ca40> @pytest.mark.parametrize("env_name", ["py", "py310", ".pkg"]) def test_allowed_implicit_cli_envs(env_name: str, tox_project: ToxProjectCreator) -> None: proj = tox_project({"tox.ini": ""}) outcome = proj.run("r", "-e", env_name) > outcome.assert_success() env_name = 'py310' outcome = code: -1 cmd: /usr/bin/python3 -m tox r -e py310 cwd: /tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_allowed_implici...uld not find python interpreter with spec(s): py310 py310: SKIP (0.23 seconds) evaluation failed :( (0.27 seconds) proj = ToxProject(path=/tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_allowed_implicit_cli_envs1/p) at 140650867026656 tox_project = <function init_fixture.<locals>._init at 0x7febd4e1ca40> tests/session/test_env_select.py:158: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = code: -1 cmd: /usr/bin/python3 -m tox r -e py310 cwd: /tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_allowed_implici...uld not find python interpreter with spec(s): py310 py310: SKIP (0.23 seconds) evaluation failed :( (0.27 seconds) def assert_success(self) -> None: > assert self.success, repr(self) # noqa: S101 E AssertionError: code: -1 E cmd: /usr/bin/python3 -m tox r -e py310 E cwd: /tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_allowed_implicit_cli_envs1/p E standard output E py310: skipped because could not find python interpreter with spec(s): py310 E py310: SKIP (0.23 seconds) E evaluation failed :( (0.27 seconds) E E assert False E + where False = code: -1\ncmd: /usr/bin/python3 -m tox r -e py310\ncwd: /tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_allowed_implicit_cli_envs1/p\nstandard output\npy310: skipped because could not find python interpreter with spec(s): py310\n py310: SKIP (0.23 seconds)\n evaluation failed :( (0.27 seconds)\n.success self = code: -1 cmd: /usr/bin/python3 -m tox r -e py310 cwd: /tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_allowed_implici...uld not find python interpreter with spec(s): py310 py310: SKIP (0.23 seconds) evaluation failed :( (0.27 seconds) .../usr/lib/python3.12/site-packages/tox/pytest.py:352: AssertionError This way, we use an environment that is available (as long as the tests run on CPython). This could be improved to support PyPy as well, but I decided to take one step at a time.
1 parent 4700298 commit 869b569

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tests/session/test_env_select.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from tox.pytest import MonkeyPatch, ToxProjectCreator
1414

1515

16+
CURRENT_PY_ENV = f"py{sys.version_info[0]}{sys.version_info[1]}" # e.g. py310
17+
18+
1619
def test_label_core_can_define(tox_project: ToxProjectCreator) -> None:
1720
ini = """
1821
[tox]
@@ -151,7 +154,7 @@ def test_cli_env_can_be_specified_in_additional_environments(tox_project: ToxPro
151154
assert not outcome.err
152155

153156

154-
@pytest.mark.parametrize("env_name", ["py", "py310", ".pkg"])
157+
@pytest.mark.parametrize("env_name", ["py", CURRENT_PY_ENV, ".pkg"])
155158
def test_allowed_implicit_cli_envs(env_name: str, tox_project: ToxProjectCreator) -> None:
156159
proj = tox_project({"tox.ini": ""})
157160
outcome = proj.run("r", "-e", env_name)

0 commit comments

Comments
 (0)