pytest - 如何根据平台有条件地设置 tox 变量

标签 pytest tox coverage.py

我的一些测试仅在 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/

相关文章:

pytest - 如何将测试标记为 "long"并跳过它们?

python - 在测试序列中的测试之间保存数据的模式

python - pytest-django依赖注入(inject)

python - Flask 保持实时服务器用于测试(Selenium)

amazon-web-services - 如何解决 botocore.exceptions.NoCredentialsError : Unable to locate credentials

python - osetests 覆盖率报告跳过了一些 .py 文件,但不确定原因

python - Pytest 项目运行速度很慢

python - tox、cython 和 fasttext

python - 查找未使用的 Django 代码以删除

python 在永无止境的进程上运行覆盖