如何根据平台有条件地设置 tox 变量
How to conditionally set tox variables depending on the platform
我的一些测试仅在 Linux 下 运行,但其他 运行 无处不在。当 运行ning 在 Linux 上时,我想将最小覆盖变量设置为比 运行ning 在我的桌面 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。
我该怎么做?
您可以定义 OS 特定环境,并为每个 OS 设置具有不同值的环境变量:
[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
文档中的参考,正如@sinoroc 在评论中指出的那样:Platform specification.
我的一些测试仅在 Linux 下 运行,但其他 运行 无处不在。当 运行ning 在 Linux 上时,我想将最小覆盖变量设置为比 运行ning 在我的桌面 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。
我该怎么做?
您可以定义 OS 特定环境,并为每个 OS 设置具有不同值的环境变量:
[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
文档中的参考,正如@sinoroc 在评论中指出的那样:Platform specification.