Skip to content

Commit 6e7459a

Browse files
ssbarneahroncok
andcommitted
Avoid exception with tox.ini containing allowlist_externals
Fixes: #45 Co-Authored-By: Miro Hrončok <[email protected]>
1 parent 931f410 commit 6e7459a

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/tox_current_env/hooks.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ def _plugin_active(option):
5454
return option.current_env or option.print_deps_to or option.print_extras_to
5555

5656

57+
def _allow_all_externals(envconfig):
58+
for option in ["allowlist_externals", "whitelist_externals"]:
59+
# If either is set, we change it, as we cannot have both set at the same time:
60+
if getattr(envconfig, option, None):
61+
setattr(envconfig, option, "*")
62+
break
63+
else:
64+
# If none was set, we set one of them, preferably the new one:
65+
if hasattr(envconfig, "allowlist_externals"):
66+
envconfig.allowlist_externals = "*"
67+
else:
68+
# unless we need to fallback to the old and deprecated
69+
# TODO, drop this when we drop support for tox < 3.18
70+
envconfig.whitelist_externals = "*"
71+
5772
@tox.hookimpl
5873
def tox_configure(config):
5974
"""Stores options in the config. Makes all commands external and skips sdist"""
@@ -72,8 +87,8 @@ def tox_configure(config):
7287
if _plugin_active(config.option):
7388
config.skipsdist = True
7489
for testenv in config.envconfigs:
75-
config.envconfigs[testenv].whitelist_externals = "*"
7690
config.envconfigs[testenv].usedevelop = False
91+
_allow_all_externals(config.envconfigs[testenv])
7792

7893
if (getattr(config.option.print_deps_to, "name", object()) ==
7994
getattr(config.option.print_extras_to, "name", object())):

tests/test_integration.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,20 @@ def test_self_is_not_installed(projdir, flag, usedevelop):
643643
assert 'test @ file://' not in result.stdout
644644

645645

646+
@pytest.mark.parametrize("externals", [None, "allowlist_externals", "whitelist_externals"])
647+
def test_externals(projdir, externals):
648+
if externals == "allowlist_externals" and TOX_VERSION < ver("3.18"):
649+
pytest.xfail("No support in old tox")
650+
with modify_config(projdir / 'tox.ini') as config:
651+
config['testenv']['commands'] = "echo assertme"
652+
if externals is not None:
653+
config['testenv'][externals] = "foo"
654+
result = tox("-e", NATIVE_TOXENV, "--current-env", quiet=False)
655+
assert result.returncode == 0
656+
assert "assertme" in result.stdout
657+
assert "test command found but not installed in testenv" not in (result.stdout + result.stderr)
658+
659+
646660
@pytest.mark.parametrize("usedevelop", [True, False])
647661
def test_self_is_installed_with_regular_tox(projdir, usedevelop):
648662
with modify_config(projdir / 'tox.ini') as config:

0 commit comments

Comments
 (0)