【问题标题】:Running tox with different environment variable config使用不同的环境变量配置运行 tox
【发布时间】:2020-05-17 08:13:24
【问题描述】:

我想用不同的环境变量值来运行我的测试。我有这个 tox.ini,它不符合我的要求:

# tox.ini

[tox]
envlist = py37-{foo,bar}

[testenv]
description = Tests common
setenv =
    MY_VAR=COMMON
commands =
    env

[testenv:foo]
description = Tests foo
setenv =
    MY_VAR=FOO

[testenv:bar]
description = Tests bar
setenv =
    MY_VAR=BAR 

ini 以上产生了以下输出:

$ tox
GLOB sdist-make: 

***

py37-foo run-test: commands[0] | env

***

MY_VAR=COMMON                                 <<<--- MY_VAR=foo is expected

***

py37-bar run-test: commands[0] | env

***

MY_VAR=COMMON                                 <<<--- MY_VAR=bar is expected

怎么了?

我用:

  • Win 10.0.18363 Build 18363
  • Python 3.7.4
  • 毒物:3.14.0

【问题讨论】:

    标签: python testing environment-variables tox


    【解决方案1】:

    tox 不结合环境。每个环境都派生自[testenv],但不考虑包含其他环境。您必须自己在tox.ini 中组合它们。这应该有效:

    [tox]
    envlist = py37-{foo,bar}
    
    [testenv]
    description = Tests common
    setenv =
        MY_VAR=COMMON
    commands =
        env
    
    [foo]
    description = Tests foo
    setenv =
        MY_VAR=FOO
    
    [bar]
    description = Tests bar
    setenv =
        MY_VAR=BAR
    
    [testenv:py37-foo]
    description = Tests py37 foo
    setenv = {[foo]setenv}
    
    [testenv:py37-bar]
    description = Tests py37 bar
    setenv = {[bar]setenv}
    

    【讨论】:

    • 谢谢,您的解决方案让我找到了我正在寻找的技术。
    【解决方案2】:

    密钥是Compressing dependency matrix。这种技术产生了紧凑且非冗余的解决方案:

    [tox]
    envlist = py37-{foo,bar,baz}
    
    [testenv]
    setenv =
        MY_VAR=COMMON
        foo: MY_VAR=FOO
        bar: MY_VAR=BAR
    commands =
        env 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 2018-11-23
      相关资源
      最近更新 更多