简体   繁体   English

在所有解释器上运行tox,包括宽和窄2.7编译的Python

[英]Running tox on all interpreters including wide and narrow 2.7 compiled Python

ruamel.yaml has a regression, introduced with a merged PR, that changed code that has essentially different paths for Python versions compiled with wide and narrow Unicode characters. ruamel.yaml具有合并PR引入的回归,该回归更改了对于使用宽和窄Unicode字符编译的Python版本具有本质上不同路径的代码。

The regression was not found during the pre-build/commit testing, because the tests , that are executed with tox were never run on a Python with narrow ('--enable-unicode=ucs2') Unicode characters. 在预构建/提交测试期间未找到回归,因为使用tox执行的测试从未在具有窄('--enable-unicode = ucs2')Unicode字符的Python上运行。 My 2.7.X is being compiled with `--enable-unicode=ucs4' and in Python 3.4+ strings have dynamic Unicode width, acting as if they are 4 byte wide for the code involved. 我的2.7.X正在使用“ --enable-unicode = ucs4”进行编译,在Python 3.4+中,字符串具有动态Unicode宽度,对于所涉及的代码而言,它们好像是4字节宽。

I have compiled a narrow version of 2.7.15. 我已经编译了2.7.15的窄版。 How can I test the narrow version along with the other Python versions (in particular the wide 2.7) in one tox run , so that when one or more of the Python versions fail, no new version is committed, and no packages are pushed to PyPI? 如何在一次tox运行中测试窄版以及其他Python版本(尤其是2.7版) ,以便当一个或多个Python版本失败时,不会提交新版本,也不会将任何包推送到PyPI ?

I tried adding a target py27m to the interpreter list used by tox-globinterpreter : 我尝试将目标py27m添加到tox-globinterpreter使用的解释器列表中:

p python2.7m /opt/python/2.7.15m/bin/python

and ran: 并运行:

tox -r -e py27m

but that did not work, as that used Python 3.6.6 to run the test (which is the interpeter tox is executed with). 但这不起作用,因为使用Python 3.6.6进行了测试(执行插入器tox )。

"Overloading" Python 2.6 in the interpreter list to use the narrow 2.7: 解释器列表中的“重载” Python 2.6使用狭窄的2.7:

p python2.6 /opt/python/2.7.15m/bin/python

didn't work either. 也不起作用。

That you cannot overload the interpreter list, probably has to do with dropped support for 2.6 (target Python3.3 and using tox -e py33 eg doesn't work either). 您不能使解释器列表超载,可能与对2.6的支持下降(目标Python3.3和使用tox -e py33 eg也不起作用)有关。 But it is relatively easy to add a specific target for py27m in your tox.ini : 但它是比较容易添加特定目标py27mtox.ini

[tox]
toxworkdir = /data2/DATA/tox/ruamel.yaml 
envlist = py36,py27,py35,py34,pypy,py27m

[testenv]
commands =
    python -c "import sys, sysconfig; print('%s ucs-%s' % (sys.version.replace('\n', ' '), sysconfig.get_config_var('Py_UNICODE_SIZE'), ))"
    /bin/bash -c 'pytest _test/test_*.py'
deps =
    pytest

[testenv:py27m]
basepython = /opt/python/2.7.15m/bin/python

The python -c ... command is to have some extra feedback on the python version installed, in particular the character width, in each of the virtualenv enviroments tox creates, as the default tox output doesn't include that. python -c ...命令将对tox创建的每个virtualenv环境中安装的python版本(尤其是字符宽度)有一些额外的反馈,因为默认的tox输出不包括该内容。 (The entries for running flake8 / codestyle in the actual tox.ini were removed for clarity). (为清楚起见,删除了实际tox.ini中用于运行flake8 / codestyle的条目)。

Together with a interpreter list ( ~/.config/tox/interpreters.lst ): 连同解释器列表( ~/.config/tox/interpreters.lst ):

v 1
# Original pattern used:
g /opt/python/?.?/bin/python?.? /opt/python/pypy2/bin/pypy 
# Interpreters found:
p python3.6 /opt/python/3.6/bin/python3.6
p python3.4 /opt/python/3.4/bin/python3.4
p python2.7 /opt/python/2.7/bin/python2.7
p python3.5 /opt/python/3.5/bin/python3.5
p python3.7 /opt/python/3.7/bin/python3.7
p pypy /opt/python/pypy2/bin/pypy
e 

, running tox -e now results in: ,运行tox -e现在会导致:

.
.
.
2.7.15 (default, Jun 30 2018, 23:05:50)  [GCC 7.3.0] ucs-4
py27m runtests: commands[1] | /bin/bash -c pytest _test/test_*.py
============================= test session starts =============================
platform linux2 -- Python 2.7.15, pytest-3.6.2, py-1.5.4, pluggy-0.6.0
.
.
.
2.7.15 (default, Jul  1 2018, 11:43:51)  [GCC 7.3.0] ucs-2
py27m runtests: commands[1] | /bin/bash -c pytest _test/test_*.py
============================= test session starts ==============================
platform linux2 -- Python 2.7.15, pytest-3.6.2, py-1.5.4, pluggy-0.6.0
.
.
.
============= 320 passed, 1 skipped, 7 xfailed in 32.36 seconds ===============
___________________________________ summary ____________________________________
  py36: commands succeeded
  py27: commands succeeded
  py35: commands succeeded
  py34: commands succeeded
  pypy: commands succeeded
  py27m: commands succeeded
  congratulations :)

This way code paths that differ for the same Python version compiled with narrow and wide Unicode can be tested in one go. 这样,可以一次性测试使用窄带和宽带Unicode编译的同一Python版本的不同代码路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM