4
4
5
5
if TYPE_CHECKING :
6
6
from tox .config .cli .parser import ToxParser
7
+ from tox .config .sets import ConfigSet
7
8
from tox .pytest import ToxProjectCreator
9
+ from tox .session .state import State
8
10
9
11
10
12
def test_inline_tox_py (tox_project : ToxProjectCreator ) -> None :
@@ -22,3 +24,37 @@ def tox_add_option(parser: ToxParser) -> None:
22
24
result = project .run ("-h" )
23
25
result .assert_success ()
24
26
assert "--magic" in result .out
27
+
28
+
29
+ def test_toxfile_py_w_ephemeral_envs (tox_project : ToxProjectCreator ) -> None :
30
+ """Ensure additional ephemeral tox envs can be plugin-injected."""
31
+ def plugin () -> None : # pragma: no cover # the code is copied to a python file
32
+ from tox .config .loader .memory import MemoryLoader # noqa: PLC0415
33
+ from tox .plugin import impl # noqa: PLC0415
34
+
35
+ env_name = "sentinel-env-name"
36
+
37
+ @impl
38
+ def tox_extend_envs () -> tuple [str ]:
39
+ return (env_name ,)
40
+
41
+ @impl
42
+ def tox_add_core_config (core_conf : ConfigSet , state : State ) -> None : # noqa: ARG001
43
+ in_memory_config_loader = MemoryLoader (
44
+ base = ["sentinel-base" ],
45
+ description = "sentinel-description" ,
46
+ )
47
+ state .conf .memory_seed_loaders [env_name ].append (
48
+ in_memory_config_loader , # src/tox/provision.py:provision()
49
+ )
50
+
51
+ project = tox_project ({"toxfile.py" : plugin })
52
+
53
+ tox_list_result = project .run ("list" , "-qq" )
54
+ tox_list_result .assert_success ()
55
+ expected_additional_env_txt = "\n \n additional environments:\n sentinel-env-name -> sentinel-description"
56
+ assert expected_additional_env_txt in tox_list_result .out
57
+
58
+ tox_config_result = project .run ("config" , "-e" , "sentinel-env-name" , "-qq" )
59
+ tox_config_result .assert_success ()
60
+ assert "base = sentinel-base" in tox_config_result .out
0 commit comments