[英]How to get tox to test "named" test environments with different python versions?
eg Let's say I have following in tox.ini例如,假设我在 tox.ini 中有关注
[tox]
envlist = py27, py35, testenv2
[testenv]
# settings related to "default" testenv - includes deps, commands
[testenv:testenv2]
# settings related to testenv2 - includes deps, commands
Now when I run tox command, it invokes testenv
commands with python 2.7 and 3.5 interpreter but testenv2
commands only with base python installed on the machine (in my case 2.7).现在,当我运行 tox 命令时,它使用 python 2.7 和 3.5 解释器调用
testenv
命令,但testenv2
命令仅在机器上安装了基本 python 的情况下调用(在我的情况下为 2.7)。 How to get tox to also test a "named" (non-default) test environment like testenv2
to be tested with multiple python versions?如何让 tox 也测试像
testenv2
这样的“命名”(非默认)测试环境,以使用多个 python 版本进行测试?
The first answer describes two viable ways.第一个答案描述了两种可行的方法。 For completeness: you can also generate environments and use conditional settings - eg:
为了完整性:您还可以生成环境并使用条件设置 - 例如:
[tox]
skipsdist = True
envlist = py{27,35}-{test,lint}
[testenv]
skip_install = True
deps =
test: pytest
test: pytest-xprocess
lint: flake8
lint: black
commands =
test: pytest -v
lint: flake8
lint: black .
would generate ( tox -a
):会生成(
tox -a
):
py27-test
py27-lint
py35-test
py35-lint
You can use any factor (eg py27 or test) to conditionally add commands, deps, etc.您可以使用任何因素(例如 py27 或 test)有条件地添加命令、deps 等。
BTW: to see which settings each testenv exactly has you can run tox --showconfig
.顺便说一句:要查看每个 testenv 究竟有哪些设置,您可以运行
tox --showconfig
。
List all environments explicitly:明确列出所有环境:
[tox]
envlist = py27, py35, py27-testenv2, py35-testenv2
If that's not enough refactor tox.ini
:如果这还不够重构
tox.ini
:
[testenv]
# settings related to "default" testenv - includes deps, commands
[testenv2]
# settings related to testenv2 - includes deps, commands
[testenv:py27-testenv2]
deps = {[testenv2]deps}
commands = {[testenv2]commands}
[testenv:py35-testenv2]
deps = {[testenv2]deps}
commands = {[testenv2]commands}
I could get the "named" test environment to be tested with multiple python versions by making multiple "named" test environments, one each for the different python versions I wanted it to be tested with and using the basepython
option to specify the python version for the test environment to be tested with.我可以通过制作多个“命名”测试环境来使用多个
basepython
版本测试“命名”测试环境,每个环境用于不同的 python 版本要测试的测试环境。 Below is the example that works:以下是有效的示例:
[tox]
envlist = py27, py35, testenv2_py27, testenv2_py35
[testenv]
# settings related to "default" testenv - includes deps, commands
[testenv:testenv2_py27]
basepython = python2.7
# settings related to testenv2 - includes deps, commands
[testenv:testenv2_py35]
basepython = python3.5
# settings related to testenv2 - includes deps, commands
Just in case someone still needs this, I figured out an even more concise solution.以防万一有人仍然需要这个,我想出了一个更简洁的解决方案。 It combines all the good suggestions from the other answers:
它结合了其他答案的所有好的建议:
[tox]
envlist = py{27,35}, testenv2-py{27,35}
[testenv]
# settings related to "default" testenv - includes deps, commands
[testenv:testenv2-py{27,35}]
# settings related to testenv2 - includes deps, commands
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.