Skip to content

Commit 4977974

Browse files
committed
test_provision_plugin_runner: testenv depends on plugin-defined runner
A testenv depends on a runner supplied via a plugin that tox needs to provision. Added the plugin to demo_pkg_inline since it seemed like the easiest place.
1 parent 7ccd0f1 commit 4977974

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/demo_pkg_inline/build.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,38 @@
1414
version = "1.0.0"
1515
dist_info = "{}-{}.dist-info".format(name, version)
1616
logic = "{}/__init__.py".format(name)
17+
plugin = "{}/example_plugin.py".format(name)
18+
entry_points = "{}/entry_points.txt".format(dist_info)
1719
metadata = "{}/METADATA".format(dist_info)
1820
wheel = "{}/WHEEL".format(dist_info)
1921
record = "{}/RECORD".format(dist_info)
2022
content = {
2123
logic: "def do():\n print('greetings from {}')".format(name),
24+
plugin: dedent(
25+
"""
26+
try:
27+
from tox.plugin import impl
28+
from tox.tox_env.python.virtual_env.runner import VirtualEnvRunner
29+
from tox.tox_env.register import ToxEnvRegister
30+
except ImportError:
31+
pass
32+
else:
33+
class ExampleVirtualEnvRunner(VirtualEnvRunner):
34+
@staticmethod
35+
def id() -> str:
36+
return "example"
37+
@impl
38+
def tox_register_tox_env(register: ToxEnvRegister) -> None:
39+
register.add_run_env(ExampleVirtualEnvRunner)
40+
""",
41+
),
42+
entry_points: dedent(
43+
"""
44+
[tox]
45+
example = {}.example_plugin""".format(
46+
name,
47+
),
48+
),
2249
metadata: """
2350
Metadata-Version: 2.1
2451
Name: {}

tests/test_provision.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,18 @@ def test_provision_no_recreate_json(tox_project: ToxProjectCreator) -> None:
187187
with (project.path / "out.json").open() as file_handler:
188188
requires = json.load(file_handler)
189189
assert requires == {"minversion": None, "requires": ["p", "tox"]}
190+
191+
192+
@pytest.mark.integration()
193+
@pytest.mark.usefixtures("_pypi_index_self")
194+
def test_provision_plugin_runner(tox_project: ToxProjectCreator, tmp_path: Path) -> None:
195+
log = tmp_path / "out.log"
196+
proj = tox_project({"tox.ini": "[tox]\nrequires=demo-pkg-inline\n[testenv]\nrunner=example"})
197+
result_first = proj.run("r", "-e", "py", "--result-json", str(log))
198+
result_first.assert_success()
199+
prov_msg = (
200+
f"ROOT: will run in automatically provisioned tox, host {sys.executable} is missing"
201+
f" [requires (has)]: demo-pkg-inline"
202+
)
203+
print(result_first.out)
204+
assert prov_msg in result_first.out

0 commit comments

Comments
 (0)