Python 2.7 tox中发布候选python版本的临时使用

Python 2.7 tox中发布候选python版本的临时使用,python-2.7,tox,tox-globinterpreter,Python 2.7,Tox,Tox Globinterpreter,我正在使用tox测试我的python包。既然Python2.7.13有了一个发行候选版本,那么如何使用tox测试这个版本,而不立即替换当前的Python2.7版本以供正常使用呢 我知道在创建virtualenv时如何为python指定路径,然后可以安装并运行py.test。Tox构建了自己的virtualenv,除了选择py27、py26、py35,我不知道如何影响安装的python版本 如何解决这个问题?您可以通过在调用tox之前扩展路径(至少在Linux上,可能不是在Windows上),使用

我正在使用
tox
测试我的python包。既然Python2.7.13有了一个发行候选版本,那么如何使用
tox
测试这个版本,而不立即替换当前的Python2.7版本以供正常使用呢

我知道在创建
virtualenv
时如何为python指定路径,然后可以安装并运行
py.test
。Tox构建了自己的virtualenv,除了选择
py27
py26
py35
,我不知道如何影响安装的python版本


如何解决这个问题?

您可以通过在调用tox之前扩展路径(至少在Linux上,可能不是在Windows上),使用路径来影响这个问题

要获得更细粒度的控制并使其在Windows上工作(在Windows中,您无法为Unix/Linux等单一命令使用设置环境变量),可以使用tox扩展包
tox globexplorer
(免责声明我是该包的作者),您可以使用
pip
安装该包

该包向
tox
添加了一个
--scan
选项,该选项写出了从
py27
py36
等到python可执行文件的显式映射

例如,我有:

tox --scan /opt/python/{2,3}.?/bin/python  /opt/python/pypy2/bin/pypy
在我的基于Linux的系统上,/opt/python/X.Y是指向安装在/opt/python/X.Y.Z中的最新发布的python版本的链接(如果是像3.6这样的开发版本,则是最新版本),这将作为输出提供:

interpreters:
python2.6 /opt/python/2.6/bin/python
python2.7 /opt/python/2.7/bin/python
python3.2 /opt/python/3.2/bin/python
python3.3 /opt/python/3.3/bin/python
python3.4 /opt/python/3.4/bin/python
python3.5 /opt/python/3.5/bin/python
python3.6 /opt/python/3.6/bin/python
pypy /opt/python/pypy2/bin/pypy
当我将扫描更改为:

tox --scan /opt/python/2.6/bin/python /opt/python/2.7.13*/bin/python \
    /opt/python/3.?/bin/python /opt/python/pypy2/bin/pypy
我得到:

interpreters:
python2.6 /opt/python/2.6/bin/python
python2.7 /opt/python/2.7.13rc1/bin/python
python3.2 /opt/python/3.2/bin/python
python3.3 /opt/python/3.3/bin/python
python3.4 /opt/python/3.4/bin/python
python3.5 /opt/python/3.5/bin/python
python3.6 /opt/python/3.6/bin/python
pypy /opt/python/pypy2/bin/pypy
tox-epy27
将使用2.7.13候选版本。如果来回切换,您可以保存配置文件(在
~/.config/tox
%APPDATA%\tox
),但重新运行扫描非常快,因此我将为此创建一个shell脚本/别名/批处理文件