Repository: tox-dev/tox

Issue:
"envlist" default with "isolated_build = true" broken
If the environment list is not specified it defaults to `python`. The following *tox.ini* works fine:

```ini
[testenv]
commands = python --version
```

On the other hand, the following *tox.ini* doesn't work:

```ini
[tox]
isolated_build = true

[testenv]
commands = python --version
```

The default `python` environment is added, if `all_envs` is empty:

https://github.com/tox-dev/tox/blob/82c26ed42b2b868b2a1e909af3453b95f277a670/src/tox/config/__init__.py#L1499-L1500

But with `isolated_build = true` the environment `.package` (or whatever the value of the option **isolated_build_env** is) gets added to `env_list` a few lines earlier (making it no longer empty):

https://github.com/tox-dev/tox/blob/82c26ed42b2b868b2a1e909af3453b95f277a670/src/tox/config/__init__.py#L1496-L1498

The section `testenv:.package` is added here:

https://github.com/tox-dev/tox/blob/82c26ed42b2b868b2a1e909af3453b95f277a670/src/tox/config/__init__.py#L1409-L1413

Discussion:
Unrud: I've added a unit test.

Patch:
diff --git a/docs/changelog/2474.bugfix.rst b/docs/changelog/2474.bugfix.rst
new file mode 100644
index 00000000..038bd96b
--- /dev/null
+++ b/docs/changelog/2474.bugfix.rst
@@ -0,0 +1,1 @@
+Fix fallback to ``python`` environment when ``isolated_build = true`` is set -- by :user:`Unrud`
diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py
index 9a2a932c..9e08725d 100644
--- a/src/tox/config/__init__.py
+++ b/src/tox/config/__init__.py
@@ -1484,7 +1484,7 @@ class ParseIni(object):
                 reader.addsubstitutions(**{env_attr.name: res})
         return tc
 
-    def _getallenvs(self, reader, extra_env_list=None):
+    def _getallenvs(self, reader, config, extra_env_list=None):
         extra_env_list = extra_env_list or []
         env_str = reader.getstring("envlist", replace=False)
         env_list = _split_env(env_str)
@@ -1493,9 +1493,12 @@ class ParseIni(object):
                 env_list.append(env)
 
         all_envs = OrderedDict((i, None) for i in env_list)
+        package_env = config.isolated_build_env if config.isolated_build is True else None
         for section in self._cfg:
             if section.name.startswith(testenvprefix):
-                all_envs[section.name[len(testenvprefix) :]] = None
+                section_env = section.name[len(testenvprefix) :]
+                if section_env != package_env:
+                    all_envs[section_env] = None
         if not all_envs:
             all_envs["python"] = None
         return list(all_envs.keys())
@@ -1511,7 +1514,7 @@ class ParseIni(object):
             (from_option and "ALL" in from_option)
             or (not from_option and from_environ and "ALL" in from_environ.split(","))
         ) and PARALLEL_ENV_VAR_KEY_PRIVATE not in os.environ:
-            all_envs = self._getallenvs(reader)
+            all_envs = self._getallenvs(reader, config)
         else:
             candidates = (
                 (os.environ.get(PARALLEL_ENV_VAR_KEY_PRIVATE), True),
@@ -1522,7 +1525,7 @@ class ParseIni(object):
             )
             env_str, envlist_explicit = next(((i, e) for i, e in candidates if i), ([], False))
             env_list = _split_env(env_str)
-            all_envs = self._getallenvs(reader, env_list)
+            all_envs = self._getallenvs(reader, config, env_list)
 
         if not env_list:
             env_list = all_envs
@@ -1533,9 +1536,6 @@ class ParseIni(object):
             raise tox.exception.ConfigError(msg)
 
         package_env = config.isolated_build_env
-        if config.isolated_build is True and package_env in all_envs:
-            all_envs.remove(package_env)
-
         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)


Test patch:
diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py
index b1a72b44..a4547260 100644
--- a/tests/unit/config/test_config.py
+++ b/tests/unit/config/test_config.py
@@ -380,6 +380,16 @@ class TestConfigPackage:
         assert config.setupdir.realpath() == tmpdir.realpath()
         assert config.toxworkdir.realpath() == tmpdir.join(".tox").realpath()
 
+    def test_defaults_isolated_build(self, newconfig):
+        config = newconfig(
+            [],
+            """
+            [tox]
+            isolated_build = true
+        """,
+        )
+        assert "python" in config.envconfigs
+
     def test_project_paths(self, tmpdir, newconfig):
         config = newconfig(
             """