Skip to content

Specify default Python(s) #2846

@stephenfin

Description

@stephenfin

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.

  1. Monkey patch tox so that the call to sys.executable returns the Python version(s) you want it to default to. This is obviously not something you should do.
  2. 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.
  3. You can take advantage of factors and create suffixed/prefixed versions of your various testenvs, so functional becomes functional{-py37,-py38,-py39,-py310}. This results in rather ugly tox.ini files and is tedious to use (tox -e functional > tox -e functional-py310).
  4. You can define base_python for 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 your tox.ini file, but at least it's nicer to use for the end user.
  5. Finally, you can define a top-level [testenv] base_python and set the [tox] ignore_base_python_conflict setting to true. This results in the simplest tox.ini file 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_conflict but make its true behaviour the default (so Python version specified via a factor always trumps base_python, without warning, if there's a conflict)
  • Don't use tox - use containers (tbc, this is not a realistic solution 😄)

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp:wantedIssues that have been acknowledged, a solution determined and a PR might likely be accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions