Skip to content

Commit 81ef83a

Browse files
committed
🧪 Add a test injecting ephemeral envs w/ plugin
1 parent d0c37b1 commit 81ef83a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

‎tests/plugin/test_inline.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
if TYPE_CHECKING:
66
from tox.config.cli.parser import ToxParser
7+
from tox.config.sets import ConfigSet
78
from tox.pytest import ToxProjectCreator
9+
from tox.session.state import State
810

911

1012
def test_inline_tox_py(tox_project: ToxProjectCreator) -> None:
@@ -22,3 +24,37 @@ def tox_add_option(parser: ToxParser) -> None:
2224
result = project.run("-h")
2325
result.assert_success()
2426
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\nadditional environments:\nsentinel-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

Comments
 (0)