Search code examples
pythonpytesttox

How to run different pytest commands on windows vs Linux with Tox?


I figured the following would work but only if I pass tox -e linux or tox -e win32 are any tests ran at all.

[testenv]
commands =
  linux: py.test {posargs}
  win32: py.test -m "not fails_on_windows" {posargs}

deps =
  pyflakes
  pytest

Solution

  • [tox]
    envlist = py39-{linux,mac,win}
    
    [testenv]
    platform =
        linux: linux
        mac: darwin
        win: win32
    commands =
      linux: py.test {posargs}
      win: py.test -m "not fails_on_windows" {posargs}
    deps =
      pyflakes
      pytest
    

    Here we create an envlist for Python 3.9 that includes the platforms Mac, Windows32 and Linux. These can then use the env specific commands. The documentation for platform specification on tox is here with included examples.