Auto-chose platform (or other) condition in tox sections

北城以北 提交于 2021-02-05 08:37:07

问题


I want to specifically run a certain tox section which then auto-decides on the specific platform. The example code-snippet below works fine if I just ran tox -e ALL. Then the platform condition nicely sects out the correct platform.

However, I want to only adress and run a specific section like for instance something like tox -e other (not tox -e other-win, other-linux) and then have tox auto-chosing the corresponding platform (or any other) condition.

I don't know if this way of setting up conditions in tox is not possible, or if I'm missing something.

[tox]
skipsdist = true

[testenv:systest-{win, linux}]
platform =
    linux: linux
    win: win|msys

whitelist_externals = 
    win: cmd
    linux: sh

commands =
    win: cmd /r echo {env:OS}
    linux: sh -c echo {env:OS}

[testenv:other-{win, linux}]
platform =
    linux: linux
    win: win|msys

whitelist_externals = 
    win: cmd
    linux: sh

commands =
    win: cmd /r echo {env:OS}
    linux: sh -c echo {env:OS}

回答1:


You could give the tox-factor plugin a try.

For example:

tox.ini

[tox]
envlist =
    alpha-{redmond,tux}
    bravo-{redmond,tux}
requires =
    tox-factor
skipsdist = true

[testenv]
commands =
    python -c 'import sys; print("platform", sys.platform)'
platform =
    redmond: win32
    tux: linux

This gives the following four environments:

$ tox --listenvs
alpha-redmond
alpha-tux
bravo-redmond
bravo-tux

That can be selected according to the factors:

$ tox --listenvs --factor tux
alpha-tux
bravo-tux
$ tox --listenvs --factor alpha
alpha-redmond
alpha-tux

And then run like this (for example on a Linux platform):

$ tox --factor bravo
bravo-tux run-test-pre: PYTHONHASHSEED='1770792708'
bravo-tux run-test: commands[0] | python -c 'import sys; print("platform", sys.platform)'
platform linux
________________________________________________ summary ________________________________________________
SKIPPED:  bravo-redmond: platform mismatch ('linux' does not match 'win32')
  bravo-tux: commands succeeded
  congratulations :)

References:

  • https://github.com/tox-dev/tox/issues/1338
  • https://pypi.org/project/tox-factor/


来源:https://stackoverflow.com/questions/62412424/auto-chose-platform-or-other-condition-in-tox-sections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!