-1

I would like to specify a few additional settings in my tox configuration, but only when I'm running on a certain platform.

For example, when running on windows I want an extra environment variable to be defined. I would like to do something like this

[tox]
envlist = env1, env2, env_win32, env_arch

[testenv]
commands= 
    do stuff...

[testenv]
platform = arch
setenv = 
    NAME = VALUE

[testenv:env_win32]
plaform = win32
more = stuff

[testenv:env_arch]
platform = arch
more = different_stuff

but this doesn't work because of the duplicate testenv section. I want the specified environment variable to apply to all environments (e.g. env1, env2, env_arch) but not on env_win32.

Note: The specific case that I'm dealing with is that on *nix platforms we need to specify an extra environment variable for install_command only, so the command includes /usr/bin/env NAME=VALUE at the beginning. Unfortunately, this doesn't exist on windows which causes it to fail. I want to conditionally define the install_command differently depending on the platform to get around this.

Ben Randall
  • 1,205
  • 10
  • 27

1 Answers1

1
[tox]
envlist = env1, env2, env_win32, env_linux

[testenv]
install_command = pip install {opts} {packages}

[testenv-linux]
platform = linux
install_command = /usr/bin/env NAME=VALUE pip install {opts} {packages}

[testenv:env_win32]
plaform = win32
install_command = {[testenv]install_command}

[testenv:env_linux]
platform = linux
install_command = {[testenv-linux]install_command}
phd
  • 82,685
  • 13
  • 120
  • 165
  • I'm not sure that this solves my problem. In my example, the commands are defined in the `[testenv]` section. If I were to run `tox -e env1` on a linux machine it would run the commands in `[testenv]` without the additional environment variable configured. – Ben Randall Dec 17 '17 at 19:36
  • Then you have to split your environments into linux- and w32-related and include proper `install_command` substitution in every environment. At least I don't see any way around that. – phd Dec 17 '17 at 20:03