diff options
-rwxr-xr-x[-rw-r--r--] | doc/example/pytest.txt | 0 | ||||
-rw-r--r-- | tests/test_config.py | 22 | ||||
-rw-r--r-- | tox/config.py | 14 |
3 files changed, 31 insertions, 5 deletions
diff --git a/doc/example/pytest.txt b/doc/example/pytest.txt index 6f98cf3..6f98cf3 100644..100755 --- a/doc/example/pytest.txt +++ b/doc/example/pytest.txt diff --git a/tests/test_config.py b/tests/test_config.py index 8b3fa1b..af77b49 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -254,6 +254,28 @@ class TestIniParserAgainstCommandsKey: ["echo", "cmd", "1", "2", "3", "4", "cmd", "2"], ] + def test_command_env_substitution(self, newconfig): + """Ensure referenced {env:key:default} values are substituted correctly.""" + config = newconfig(""" + [testenv:py27] + setenv = + TEST=testvalue + commands = + ls {env:TEST} + """) + reader = SectionReader("testenv:py27", config._cfg) + x = reader.getargvlist("commands") + assert x == [ + "ls testvalue".split() + ] + assert x != [ + "ls {env:TEST}".split() + ] + y = reader.getargvlist("setenv") + assert y == [ + "TEST=testvalue".split() + ] + class TestIniParser: def test_getstring_single(self, tmpdir, newconfig): diff --git a/tox/config.py b/tox/config.py index a4334d6..1c16c36 100644 --- a/tox/config.py +++ b/tox/config.py @@ -902,6 +902,7 @@ class SectionReader: return '\n'.join(filter(None, map(factor_line, lines))) def _replace_env(self, match): + env_list = self.getdict('setenv') match_value = match.group('substitution_value') if not match_value: raise tox.exception.ConfigError( @@ -916,11 +917,14 @@ class SectionReader: envkey = match_value if envkey not in os.environ and default is None: - raise tox.exception.ConfigError( - "substitution env:%r: unknown environment variable %r" % - (envkey, envkey)) - - return os.environ.get(envkey, default) + if envkey not in env_list and default is None: + raise tox.exception.ConfigError( + "substitution env:%r: unknown environment variable %r" % + (envkey, envkey)) + if envkey in os.environ: + return os.environ.get(envkey, default) + else: + return env_list.get(envkey, default) def _substitute_from_other_section(self, key): if key.startswith("[") and "]" in key: |