You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否为同一配置绑定多个testenv标签以复用tox脚本?

Can I reuse tox testenv configurations by binding multiple labels?

Yes, absolutely! Tox fully supports grouping multiple test environment names in a single [testenv:<names>] section to eliminate repetitive configuration code—this is exactly the right approach to clean up your current setup.

How to implement your proposed approach

Your example syntax is valid. You can group environments that share identical settings (like your Python 3.x Jenkins envs) under one section. For your specific case, split the Python 2 and Python 3 environments into two grouped sections since they only differ in the basepython value:

# Group Python 3.x Jenkins environments
[testenv:py3.6.4-jenkins,py3.5.4-jenkins,py3-jenkins]
basepython = python3
commands = {toxinidir}/jenkins.sh
setenv =
    STANFORD_MODELS = {homedir}/third/stanford-parser/
    STANFORD_PARSER = {homedir}/third/stanford-parser/
    STANFORD_POSTAGGER = {homedir}/third/stanford-postagger/

# Separate Python 2.7 Jenkins environment (uses different basepython)
[testenv:py2.7.14-jenkins]
basepython = python
commands = {toxinidir}/jenkins.sh
setenv =
    STANFORD_MODELS = {homedir}/third/stanford-parser/
    STANFORD_PARSER = {homedir}/third/stanford-parser/
    STANFORD_POSTAGGER = {homedir}/third/stanford-postagger/

Even better: Use Tox's default testenv inheritance

To cut down on duplication even more, define shared settings in a top-level [testenv] section, then override only the differing values in specific environment groups. This way you won’t have to repeat commands and setenv across sections:

# Default shared configuration for all Jenkins envs
[testenv]
commands = {toxinidir}/jenkins.sh
setenv =
    STANFORD_MODELS = {homedir}/third/stanford-parser/
    STANFORD_PARSER = {homedir}/third/stanford-parser/
    STANFORD_POSTAGGER = {homedir}/third/stanford-postagger/

# Override basepython for Python 3.x envs
[testenv:py3.6.4-jenkins,py3.5.4-jenkins,py3-jenkins]
basepython = python3

# Override basepython for Python 2.7 env
[testenv:py2.7.14-jenkins]
basepython = python

This inheritance model keeps your tox.ini clean and maintainable—any changes to shared commands or environment variables only need to be made once in the [testenv] section.

内容的提问来源于stack exchange,提问作者alvas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:35:13