Unexpected setenv behavior

Issue #137 on hold
Chris Jerdonek created an issue

The following behavior was unexpected to me. With an ini section like the following:

[testenv]
setenv = FOO = bar
commands = echo {env:FOO}

The environment variable FOO set via setenv is not reflected in the {env:FOO} substitution. I think the documentation should clarify this because it may be surprising to some. Also, there is a typo here (unkown -> unknown).

Comments (6)

  1. Holger Krekel repo owner

    Agreed, this should be fixed, actually. setenv should work for substitutions in commands.

  2. Chris Jerdonek reporter

    Hmm, this might become subtle then, or not so simple to document. If {env:*} needs to respect setenv, then the behavior could get complicated with things like the following (here is a simple case):

    setenv =
      FOO = 1000
      BAR = {env:FOO}
    

    Currently, because {env:*} expands to the values at start-up, there is never any ambiguity.

  3. Holger Krekel repo owner

    You are right. The implementation might not be a few lines of change.

    FYI I am actually unhappy about the "up front" expansion on all configs. It should be more lazy. For example, i once had a specific test environment that depended on an environment variable. The environment was not part of envlist, though. I only wanted to execute it sometimes and would be fine if tox gets back to me saying it needs that env variable. As it stands, however, this doesn't work because all environments need to properly expand up-front even if some of them are not actually needed. I haven't really looked into what is needed to make things more lazy. Hopefully it is a change that can be confined to config.py mostly.

  4. Chris Jerdonek reporter

    I think the trickiest thing will be deciding the rules for what behavior you want. For example, should it be procedurally evaluated (i.e. dependent on the order in which directives are processed), or declarative (i.e. order independent). An example of this is whether it matters if the setenv directives come before or after the substitutions they might affect.

  5. Log in to comment