From 6e7459afce5169fe566b0dd167de748971f9abf1 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 14 Dec 2021 08:39:46 +0000 Subject: [PATCH] Avoid exception with tox.ini containing allowlist_externals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/fedora-python/tox-current-env/issues/45 Co-Authored-By: Miro HronĨok --- src/tox_current_env/hooks.py | 17 ++++++++++++++++- tests/test_integration.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index 80de07d..b7337ea 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -54,6 +54,21 @@ def _plugin_active(option): return option.current_env or option.print_deps_to or option.print_extras_to +def _allow_all_externals(envconfig): + for option in ["allowlist_externals", "whitelist_externals"]: + # If either is set, we change it, as we cannot have both set at the same time: + if getattr(envconfig, option, None): + setattr(envconfig, option, "*") + break + else: + # If none was set, we set one of them, preferably the new one: + if hasattr(envconfig, "allowlist_externals"): + envconfig.allowlist_externals = "*" + else: + # unless we need to fallback to the old and deprecated + # TODO, drop this when we drop support for tox < 3.18 + envconfig.whitelist_externals = "*" + @tox.hookimpl def tox_configure(config): """Stores options in the config. Makes all commands external and skips sdist""" @@ -72,8 +87,8 @@ def tox_configure(config): if _plugin_active(config.option): config.skipsdist = True for testenv in config.envconfigs: - config.envconfigs[testenv].whitelist_externals = "*" config.envconfigs[testenv].usedevelop = False + _allow_all_externals(config.envconfigs[testenv]) if (getattr(config.option.print_deps_to, "name", object()) == getattr(config.option.print_extras_to, "name", object())): diff --git a/tests/test_integration.py b/tests/test_integration.py index 816b38d..6be2adb 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -643,6 +643,20 @@ def test_self_is_not_installed(projdir, flag, usedevelop): assert 'test @ file://' not in result.stdout +@pytest.mark.parametrize("externals", [None, "allowlist_externals", "whitelist_externals"]) +def test_externals(projdir, externals): + if externals == "allowlist_externals" and TOX_VERSION < ver("3.18"): + pytest.xfail("No support in old tox") + with modify_config(projdir / 'tox.ini') as config: + config['testenv']['commands'] = "echo assertme" + if externals is not None: + config['testenv'][externals] = "foo" + result = tox("-e", NATIVE_TOXENV, "--current-env", quiet=False) + assert result.returncode == 0 + assert "assertme" in result.stdout + assert "test command found but not installed in testenv" not in (result.stdout + result.stderr) + + @pytest.mark.parametrize("usedevelop", [True, False]) def test_self_is_installed_with_regular_tox(projdir, usedevelop): with modify_config(projdir / 'tox.ini') as config: