-
-
Notifications
You must be signed in to change notification settings - Fork 549
Specify default Python(s) #2846
Description
What's the problem this feature will solve?
tox defaults to using the Python version that tox itself is installed under (retrieved via sys.executable) for testenvs that do not contain a Python factor (e.g. py38) or have not defined a base_python / basepython setting. This version varies depending on the user's environment: a contributor using Ubuntu 22.04 will have a default Python version of 3.10, while a contributor using Fedora 37 would have a default Python version of 3.11. This means a test run on one environment may result in different results that a test run in another. This harms reproducibility and leads to confusion. Worse, this can result in failures for users in environments with recent Python versions (e.g. Fedora users) as the package under test or one of its dependencies may not yet support newer Python versions.
Currently, there are a few separate ways to resolve this.
- Monkey patch
toxso that the call tosys.executablereturns the Python version(s) you want it to default to. This is obviously not something you should do. - You can insist that users install tox under a given interpreter version. This is error prone (users need to read documentation), does not allow (Linux) users to take advantage of distro-provided packages that are automatically updated, and generally feels kind of ugly.
- You can take advantage of factors and create suffixed/prefixed versions of your various testenvs, so
functionalbecomesfunctional{-py37,-py38,-py39,-py310}. This results in rather uglytox.inifiles and is tedious to use (tox -e functional>tox -e functional-py310). - You can define
base_pythonfor every environment that does not contain a Python factor. Again, this is rather tedious (particularly for projects with a large number of testenvs) and prone to mistakes when writing yourtox.inifile, but at least it's nicer to use for the end user. - Finally, you can define a top-level
[testenv] base_pythonand set the[tox] ignore_base_python_conflictsetting totrue. This results in the simplesttox.inifile and is easy to run.
Currently, 5. provides the nicest blend between tox.ini simplicity and end-user usability. Unfortunately though, there is talk of the [tox] ignore_base_python_conflict setting being removed meaning this option might not be available in the future.
Describe the solution you'd like
I would like to be able to specify a global default Python version to be used when a Python version is not already defined via a factor. Put another way, I want a user-configurable way to override the default version derived sys.executable.
Alternative Solutions
- Do not deprecate
ignore_base_python_conflict. - Remove
ignore_base_python_conflictbut make itstruebehaviour the default (so Python version specified via a factor always trumpsbase_python, without warning, if there's a conflict) - Don't use
tox- use containers (tbc, this is not a realistic solution 😄)