diff options
author | Bernat Gabor <gaborjbernat@gmail.com> | 2018-09-14 18:39:05 +0100 |
---|---|---|
committer | Bernát Gábor <gaborjbernat@gmail.com> | 2018-09-14 21:53:35 +0300 |
commit | e4645ecea2a1ffcff769d9891a3080f2c90db8f7 (patch) | |
tree | 52abade333e4a383d910dba0e9592ea001cdd8bf | |
parent | 2d4224661c67a5be5d912f6c1616a3cc73cb41ad (diff) | |
download | tox-git-e4645ecea2a1ffcff769d9891a3080f2c90db8f7.tar.gz |
keep additional environments config order #921
-rw-r--r-- | changelog/921.feature.rst | 1 | ||||
-rwxr-xr-x | src/tox/config.py | 18 | ||||
-rw-r--r-- | src/tox/session.py | 2 | ||||
-rw-r--r-- | tests/unit/session/test_list_env.py | 42 | ||||
-rw-r--r-- | tests/unit/test_config.py | 4 |
5 files changed, 57 insertions, 10 deletions
diff --git a/changelog/921.feature.rst b/changelog/921.feature.rst new file mode 100644 index 00000000..7a061b95 --- /dev/null +++ b/changelog/921.feature.rst @@ -0,0 +1 @@ +keep additional environments config order when listing them - by :user:`gaborbernat` diff --git a/src/tox/config.py b/src/tox/config.py index e9f55c99..a7e62d52 100755 --- a/src/tox/config.py +++ b/src/tox/config.py @@ -10,6 +10,7 @@ import string import sys import uuid import warnings +from collections import OrderedDict from fnmatch import fnmatchcase from subprocess import list2cmdline @@ -783,7 +784,7 @@ class Config(object): """Global Tox config object.""" def __init__(self, pluginmanager, option, interpreters, parser): - self.envconfigs = {} + self.envconfigs = OrderedDict() """Mapping envname -> envconfig""" self.invocationcwd = py.path.local() self.interpreters = interpreters @@ -1110,25 +1111,28 @@ class ParseIni(object): env_list = _split_env(env_str) # collect section envs - all_envs = set(env_list) - {"ALL"} + all_envs = OrderedDict((i, None) for i in env_list) + if "ALL" in all_envs: + all_envs.pop("ALL") for section in self._cfg: if section.name.startswith(testenvprefix): - all_envs.add(section.name[len(testenvprefix) :]) + all_envs[section.name[len(testenvprefix) :]] = None if not all_envs: - all_envs.add("python") + all_envs["python"] = None package_env = config.isolated_build_env if config.isolated_build is True and package_env in all_envs: - all_envs.remove(package_env) + all_envs.pop(package_env) if not env_list or "ALL" in env_list: - env_list = sorted(all_envs) + env_list = list(all_envs.keys()) if config.isolated_build is True and package_env in env_list: msg = "isolated_build_env {} cannot be part of envlist".format(package_env) raise tox.exception.ConfigError(msg) - return env_list, all_envs + all_env_list = list(all_envs.keys()) + return env_list, all_env_list def _split_env(env): diff --git a/src/tox/session.py b/src/tox/session.py index 5ac0c7d3..97e5da19 100644 --- a/src/tox/session.py +++ b/src/tox/session.py @@ -621,7 +621,7 @@ class Session: env_conf = self.config.envconfigs # this contains all environments default = self.config.envlist # this only the defaults ignore = {self.config.isolated_build_env}.union(default) - extra = sorted(e for e in env_conf if e not in ignore) if all_envs else [] + extra = [e for e in env_conf if e not in ignore] if all_envs else [] if description: self.report.line("default environments:") diff --git a/tests/unit/session/test_list_env.py b/tests/unit/session/test_list_env.py index 8ccee897..e48e532a 100644 --- a/tests/unit/session/test_list_env.py +++ b/tests/unit/session/test_list_env.py @@ -150,3 +150,45 @@ def test_listenvs_packaging_excluded(cmd, initproj): result = cmd("-a") expected = ["py36", "py27", "py34", "pypi", "docs", "notincluded"] assert result.outlines == expected, result.outlines + + +def test_listenvs_all_extra_definition_order_decreasing(cmd, initproj): + initproj( + "listenvs_all", + filedefs={ + "tox.ini": """ + [tox] + envlist=py36 + + [testenv:b] + changedir = whatever + + [testenv:a] + changedir = docs + """ + }, + ) + result = cmd("-a") + expected = ["py36", "b", "a"] + assert result.outlines == expected + + +def test_listenvs_all_extra_definition_order_increasing(cmd, initproj): + initproj( + "listenvs_all", + filedefs={ + "tox.ini": """ + [tox] + envlist=py36 + + [testenv:a] + changedir = whatever + + [testenv:b] + changedir = docs + """ + }, + ) + result = cmd("-a") + expected = ["py36", "a", "b"] + assert result.outlines == expected diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index d4d940f7..8b5d2285 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -1833,9 +1833,9 @@ class TestGlobalOptions: assert config.envlist == ["py35", "py36"] monkeypatch.setenv("TOXENV", "ALL") config = newconfig([], inisource) - assert config.envlist == ["py27", "py35", "py36"] + assert config.envlist == ["py36", "py35", "py27"] config = newconfig(["-eALL"], inisource) - assert config.envlist == ["py27", "py35", "py36"] + assert config.envlist == ["py36", "py35", "py27"] config = newconfig(["-espam"], inisource) assert config.envlist == ["spam"] |