mirror of
https://github.com/fedora-python/tox-current-env.git
synced 2024-12-25 01:26:13 +01:00
Avoid exception with tox.ini containing allowlist_externals
Fixes: https://github.com/fedora-python/tox-current-env/issues/45 Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
This commit is contained in:
parent
931f41066b
commit
6e7459afce
@ -54,6 +54,21 @@ def _plugin_active(option):
|
|||||||
return option.current_env or option.print_deps_to or option.print_extras_to
|
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
|
@tox.hookimpl
|
||||||
def tox_configure(config):
|
def tox_configure(config):
|
||||||
"""Stores options in the config. Makes all commands external and skips sdist"""
|
"""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):
|
if _plugin_active(config.option):
|
||||||
config.skipsdist = True
|
config.skipsdist = True
|
||||||
for testenv in config.envconfigs:
|
for testenv in config.envconfigs:
|
||||||
config.envconfigs[testenv].whitelist_externals = "*"
|
|
||||||
config.envconfigs[testenv].usedevelop = False
|
config.envconfigs[testenv].usedevelop = False
|
||||||
|
_allow_all_externals(config.envconfigs[testenv])
|
||||||
|
|
||||||
if (getattr(config.option.print_deps_to, "name", object()) ==
|
if (getattr(config.option.print_deps_to, "name", object()) ==
|
||||||
getattr(config.option.print_extras_to, "name", object())):
|
getattr(config.option.print_extras_to, "name", object())):
|
||||||
|
@ -643,6 +643,20 @@ def test_self_is_not_installed(projdir, flag, usedevelop):
|
|||||||
assert 'test @ file://' not in result.stdout
|
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])
|
@pytest.mark.parametrize("usedevelop", [True, False])
|
||||||
def test_self_is_installed_with_regular_tox(projdir, usedevelop):
|
def test_self_is_installed_with_regular_tox(projdir, usedevelop):
|
||||||
with modify_config(projdir / 'tox.ini') as config:
|
with modify_config(projdir / 'tox.ini') as config:
|
||||||
|
Loading…
Reference in New Issue
Block a user