我的一些测试仅在 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,在其他平台上将 MINCOVERAGE 设置为 35。
我怎样才能做到这一点?
最佳答案
您可以定义特定于操作系统的环境,并为每个操作系统设置具有不同值的环境变量:
[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 .
关于pytest - 如何根据平台有条件地设置 tox 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61510250/