Tox basepython and Python3

Sean Mooney smooney at redhat.com
Mon May 11 20:02:47 UTC 2020


On Mon, 2020-05-11 at 10:34 -0700, Clark Boylan wrote:
> Hello everyone,
> 
> This has come up a few times on IRC so we are probably well overdue for a email about it. Long story short, if your
> tox.ini config sets basepython [0] to `python3` and you also use py35, py36, py37, or py38 test targets there is a
> good chance you are not testing what you intend to be testing. You also need to set ignore_basepython_conflict to true
> [1].
> 
> The reason for this is basepython acts as an override for the python executable to be used when creating tox
> virtualenvs. `python3` on most platforms indicates a specific python3 version: Ubuntu Xenial 3.5, Ubuntu Bionic and
> CentOS 8 3.6, and so on. This means that even though you are asking for python 3.7 via py37 you'll get whatever
> version `python3` is on the running platform. To address this we can set ignore_basepython_conflict and tox will use
> the version specified as part of the target and not the basepython override.
> 
> You might wonder why using basepython is useful at all given this situation. The reason for it is the default python
> used by tox for virtualenvs is the version of python tox was installed under. This means that if tox is running under
> python2 it will use python2 for virtualenvs when no other version is set. Since many software projects are now trying
> to drop python2 support they want to explicitly force python3 in the default case. basepython gets us halfway there,
> ignore_basepython_conflict the rest of the way.
> 
> [0] https://tox.readthedocs.io/en/latest/config.html#conf-basepython
> [1] https://tox.readthedocs.io/en/latest/config.html#conf-ignore_basepython_conflict
> 
> Hopefully this helps explain some of tox's odd behavior in a beneficial way. Now go and check your tox.ini files :)
yep and to reinforce that point we also have this big warning comment nova so that people know  why we do this.
https://github.com/openstack/nova/blob/master/tox.ini#L4-L7
in later version of tox ignore_basepython_conflict = True will be the default
as that is generally less surprisng behavior but with our current min version both are needed.
> Clark
> 




More information about the openstack-discuss mailing list