diff options
author | Masen Furer <m_github@0x26.net> | 2023-01-16 14:08:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-16 14:08:26 -0800 |
commit | e4c65bb1fef704aadc6192679f21a55dfeee9c62 (patch) | |
tree | 82b4a7637212019e4a9b8071d91af8cb23cb57dc /tests | |
parent | a2222e98b320467e821cf9444113e9b40ab3ad1b (diff) | |
download | tox-git-e4c65bb1fef704aadc6192679f21a55dfeee9c62.tar.gz |
Provision: ignore other test environments (#2865)
Fix https://github.com/tox-dev/tox/issues/2862
Diffstat (limited to 'tests')
-rw-r--r-- | tests/demo_pkg_inline/build.py | 27 | ||||
-rw-r--r-- | tests/test_provision.py | 25 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/demo_pkg_inline/build.py b/tests/demo_pkg_inline/build.py index 35e22f03..47df3a3d 100644 --- a/tests/demo_pkg_inline/build.py +++ b/tests/demo_pkg_inline/build.py @@ -14,11 +14,38 @@ pkg_name = name.replace("_", "-") version = "1.0.0" dist_info = "{}-{}.dist-info".format(name, version) logic = "{}/__init__.py".format(name) +plugin = "{}/example_plugin.py".format(name) +entry_points = "{}/entry_points.txt".format(dist_info) metadata = "{}/METADATA".format(dist_info) wheel = "{}/WHEEL".format(dist_info) record = "{}/RECORD".format(dist_info) content = { logic: "def do():\n print('greetings from {}')".format(name), + plugin: dedent( + """ + try: + from tox.plugin import impl + from tox.tox_env.python.virtual_env.runner import VirtualEnvRunner + from tox.tox_env.register import ToxEnvRegister + except ImportError: + pass + else: + class ExampleVirtualEnvRunner(VirtualEnvRunner): + @staticmethod + def id() -> str: + return "example" + @impl + def tox_register_tox_env(register: ToxEnvRegister) -> None: + register.add_run_env(ExampleVirtualEnvRunner) + """, + ), + entry_points: dedent( + """ + [tox] + example = {}.example_plugin""".format( + name, + ), + ), metadata: """ Metadata-Version: 2.1 Name: {} diff --git a/tests/test_provision.py b/tests/test_provision.py index c7a7fac2..91d7689d 100644 --- a/tests/test_provision.py +++ b/tests/test_provision.py @@ -187,3 +187,28 @@ def test_provision_no_recreate_json(tox_project: ToxProjectCreator) -> None: with (project.path / "out.json").open() as file_handler: requires = json.load(file_handler) assert requires == {"minversion": None, "requires": ["p", "tox"]} + + +@pytest.mark.integration() +@pytest.mark.usefixtures("_pypi_index_self") +@pytest.mark.parametrize("plugin_testenv", ["testenv", "testenv:a"]) +def test_provision_plugin_runner(tox_project: ToxProjectCreator, tmp_path: Path, plugin_testenv: str) -> None: + """Ensure that testenv runner doesn't affect the provision env.""" + log = tmp_path / "out.log" + proj = tox_project({"tox.ini": f"[tox]\nrequires=demo-pkg-inline\n[{plugin_testenv}]\nrunner=example"}) + result_first = proj.run("r", "-e", "py", "--result-json", str(log)) + result_first.assert_success() + prov_msg = ( + f"ROOT: will run in automatically provisioned tox, host {sys.executable} is missing" + f" [requires (has)]: demo-pkg-inline" + ) + assert prov_msg in result_first.out + + +@pytest.mark.integration() +def test_provision_plugin_runner_in_provision(tox_project: ToxProjectCreator, tmp_path: Path) -> None: + """Ensure that provision environment can be explicitly configured.""" + log = tmp_path / "out.log" + proj = tox_project({"tox.ini": "[tox]\nrequires=somepkg123xyz\n[testenv:.tox]\nrunner=example"}) + with pytest.raises(KeyError, match="example"): + proj.run("r", "-e", "py", "--result-json", str(log)) |