【问题标题】:How to get tox to test "named" test environments with different python versions?如何让 tox 测试具有不同 python 版本的“命名”测试环境?
【发布时间】:2018-09-24 02:16:24
【问题描述】:

例如假设我在 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 版本进行测试?

【问题讨论】:

    标签: python testing tox


    【解决方案1】:

    第一个答案描述了两种可行的方法。为了完整性:您还可以生成环境并使用条件设置 - 例如:

    [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 等。

    另请参阅docs

    顺便说一句:要查看每个 testenv 究竟有哪些设置,您可以运行 tox --showconfig

    【讨论】:

      【解决方案2】:

      明确列出所有环境:

      [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}
      

      【讨论】:

      • 第一种方法行不通。我没有尝试第二种方式,但找到了另一种类似于你的方式。很快就会发布答案
      【解决方案3】:

      我可以通过创建多个“命名”测试环境来使用多个 python 版本测试“命名”测试环境,每个环境用于我想要测试的不同 python 版本,并使用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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-22
        • 1970-01-01
        • 1970-01-01
        • 2019-08-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多