Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionally set tox variables depending on the platform

Some of my tests only run under Linux, but others run everywhere. I'd like to set the minimum coverage variable to a higher value when running on Linux, than when running on my desktop Mac.

How can I do that?

Here's a bit of my 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

I'd like to set MINCOVERAGE to 70 when on Linux, and 35 when on other platforms.

How can I do that?

like image 957
Alan Robertson Avatar asked Nov 30 '25 03:11

Alan Robertson


1 Answers

You can define OS-specific environments and set an environment variable with different value for each 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}

Reference in tox docs, as pointed out by @sinoroc in the comments: Platform specification.

like image 53
hoefling Avatar answered Dec 03 '25 09:12

hoefling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!