【问题标题】:How to conditionally set tox variables depending on the platform如何根据平台有条件地设置tox变量
【发布时间】:2020-08-14 00:58:03
【问题描述】:

我的一些测试只在 Linux 下运行,而另一些则可以在任何地方运行。在 Linux 上运行时,我想将最小覆盖率变量设置为比在我的桌面 Mac 上运行时更高的值。

我该怎么做?

这是我的 tox.ini 的一点:

[tox]
MINCOVERAGE = 35
envlist = py37

[testenv]
commands =
    pytest -v -v -x --fulltrace --tb=long --showlocals \
    --cov={envsitepackagesdir}/secretsapi --cov-report=html --no-cov-on-fail \
    --cov-fail-under={[tox]MINCOVERAGE} mypackage/tests

我想在 Linux 上将 MINCOVERAGE 设置为 70,在其他平台上设置为 35。

我该怎么做?

【问题讨论】:

    标签: pytest tox coverage.py


    【解决方案1】:

    您可以定义特定于操作系统的环境并为每个操作系统设置具有不同值的环境变量:

    [tox]
    envlist = py37-{linux,mac,win}
    
    [testenv]
    platform =
        linux: linux
        mac: darwin
        win: win32
    deps =
        pytest
        pytest-cov
    setenv =
        MINCOVERAGE = 35  # default for mac, win
        linux: MINCOVERAGE = 70  # special for linux
    commands =
        pytest ... --cov-fail-under={env:MINCOVERAGE}
    

    tox 文档中的参考,正如 cmets 中的@sinoroc 所指出的那样:Platform specification

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    相关资源
    最近更新 更多