在tox中临时使用release candidate python版本

时间:2016-12-04 16:07:51

标签: python-2.7 tox tox-globinterpreter

我正在使用tox来测试我的python包。现在python 2.7.13有一个候选版本,如何使用tox测试此版本而不立即替换我当前的python 2.7版本以供正常使用?

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

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可以使用PATH对此进行影响,方法是在调用tox之前扩展PATH(至少在Linux上,可能不在Windows上)。

要获得更精细的控制并使其在Windows上运行(在AFAIK中,您无法为Unix / Linux上的单个命令使用设置环境变量),您可以使用tox扩展包{{1} (免责声明我是该软件包的作者),您可以使用tox-globinterpreter安装。

该包向pip添加--scan选项,该选项写出从toxpy27等到python可执行文件的显式映射。

E.g。我这样做:

py36

在我的基于Linux的系统上,其中/ opt / python / XY是安装在/ opt / python / XYZ中的最新发布的 Python版本的链接(或者是开发时的最新版本)版本如3.6),这给出了输出:

tox --scan /opt/python/{2,3}.?/bin/python  /opt/python/pypy2/bin/pypy

当我将扫描更改为:

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 将使用2.7.13候选版本。如果来回切换,您可以保存配置文件(在tox -e py27~/.config/tox中),但是重新运行扫描非常快,所以我会为此创建一个shell脚本/别名/批处理文件。 / p>