[英]CircleCI for simple Python project with tox: how to test multiple Python environments?
[英]How to get tox to test "named" test environments with different python versions?
例如,假设我在 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
现在,当我运行 tox 命令时,它使用 python 2.7 和 3.5 解释器调用testenv
命令,但testenv2
命令仅在机器上安装了基本 python 的情况下调用(在我的情况下为 2.7)。 如何让 tox 也测试像testenv2
这样的“命名”(非默认)测试环境,以使用多个 python 版本进行测试?
第一个答案描述了两种可行的方法。 为了完整性:您还可以生成环境并使用条件设置 - 例如:
[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 .
会生成( tox -a
):
py27-test
py27-lint
py35-test
py35-lint
您可以使用任何因素(例如 py27 或 test)有条件地添加命令、deps 等。
另请参阅文档。
顺便说一句:要查看每个 testenv 究竟有哪些设置,您可以运行tox --showconfig
。
明确列出所有环境:
[tox]
envlist = py27, py35, py27-testenv2, py35-testenv2
如果这还不够重构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}
我可以通过制作多个“命名”测试环境来使用多个basepython
版本测试“命名”测试环境,每个环境用于不同的 python 版本要测试的测试环境。 以下是有效的示例:
[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
以防万一有人仍然需要这个,我想出了一个更简洁的解决方案。 它结合了其他答案的所有好的建议:
[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.