diff options
author | Bernát Gábor <bgabor8@bloomberg.net> | 2019-05-01 05:52:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-01 05:52:59 -0400 |
commit | 7a2edd942602a4ad9b0efd16b8f92e3d7b16f4be (patch) | |
tree | b0a6c5e23e2a7156efc876120792e6c27484cad8 | |
parent | 12eb2b6a82960508de285289657ef6658b323d94 (diff) | |
download | tox-git-7a2edd942602a4ad9b0efd16b8f92e3d7b16f4be.tar.gz |
do not allow setting the ``TOXENV`` or the ``-e` flag to override the listed default environment variables, these show up under extra (#1284)
-rw-r--r-- | docs/changelog/720.bugfix.rst | 1 | ||||
-rw-r--r-- | src/tox/config/__init__.py | 4 | ||||
-rw-r--r-- | src/tox/session/commands/show_env.py | 2 | ||||
-rw-r--r-- | tests/unit/session/test_list_env.py | 25 |
4 files changed, 28 insertions, 4 deletions
diff --git a/docs/changelog/720.bugfix.rst b/docs/changelog/720.bugfix.rst new file mode 100644 index 00000000..6b17d8a7 --- /dev/null +++ b/docs/changelog/720.bugfix.rst @@ -0,0 +1 @@ +fix for ``tox -l`` command: do not allow setting the ``TOXENV`` or the ``-e`` flag to override the listed default environment variables, they still show up under extra if non defined target - by :user:`gaborbernat` diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 70aa45a3..adfa81fb 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -1063,7 +1063,7 @@ class ParseIni(object): self.handle_provision(config, reader) self.parse_build_isolation(config, reader) - config.envlist, all_envs = self._getenvdata(reader, config) + config.envlist, all_envs, config.envlist_default = self._getenvdata(reader, config) # factors used in config or predefined known_factors = self._list_section_factors("testenv") @@ -1251,7 +1251,7 @@ class ParseIni(object): 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 + return env_list, all_envs, _split_env(from_config) def _split_env(env): diff --git a/src/tox/session/commands/show_env.py b/src/tox/session/commands/show_env.py index f741234a..72e49db3 100644 --- a/src/tox/session/commands/show_env.py +++ b/src/tox/session/commands/show_env.py @@ -5,7 +5,7 @@ from tox import reporter as report def show_envs(config, all_envs=False, description=False): env_conf = config.envconfigs # this contains all environments - default = config.envlist # this only the defaults + default = config.envlist_default # this only the defaults ignore = {config.isolated_build_env, config.provision_tox_env}.union(default) extra = [e for e in env_conf if e not in ignore] if all_envs else [] diff --git a/tests/unit/session/test_list_env.py b/tests/unit/session/test_list_env.py index 36404903..8281a829 100644 --- a/tests/unit/session/test_list_env.py +++ b/tests/unit/session/test_list_env.py @@ -20,6 +20,18 @@ def test_listenvs(cmd, initproj, monkeypatch): """ }, ) + + result = cmd("-l") + assert result.outlines == ["py36", "py27", "py34", "pypi", "docs"] + + result = cmd("-l", "-e", "py") + assert result.outlines == ["py36", "py27", "py34", "pypi", "docs"] + + monkeypatch.setenv(str("TOXENV"), str("py")) + result = cmd("-l") + assert result.outlines == ["py36", "py27", "py34", "pypi", "docs"] + + monkeypatch.setenv(str("TOXENV"), str("py36")) result = cmd("-l") assert result.outlines == ["py36", "py27", "py34", "pypi", "docs"] @@ -60,7 +72,7 @@ def test_listenvs_verbose_description(cmd, initproj): assert result.outlines[2:] == expected -def test_listenvs_all(cmd, initproj): +def test_listenvs_all(cmd, initproj, monkeypatch): initproj( "listenvs_all", filedefs={ @@ -80,6 +92,17 @@ def test_listenvs_all(cmd, initproj): expected = ["py36", "py27", "py34", "pypi", "docs", "notincluded"] assert result.outlines == expected + result = cmd("-a", "-e", "py") + assert result.outlines == ["py36", "py27", "py34", "pypi", "docs", "py", "notincluded"] + + monkeypatch.setenv(str("TOXENV"), str("py")) + result = cmd("-a") + assert result.outlines == ["py36", "py27", "py34", "pypi", "docs", "py", "notincluded"] + + monkeypatch.setenv(str("TOXENV"), str("py36")) + result = cmd("-a") + assert result.outlines == ["py36", "py27", "py34", "pypi", "docs", "notincluded"] + def test_listenvs_all_verbose_description(cmd, initproj): initproj( |