Skip to content

Commit

Permalink
Passenv: Include default env variables regardless of their case on UNIX
Browse files Browse the repository at this point in the history
This fixes problems with environment variables
that are also used in their lower-case form,
such as http_proxy and https_proxy.
This applies only to UNIX systems since Windows is case-insensitive.

Closes #2372
  • Loading branch information
Fabian Poggenhans committed Mar 11, 2022
1 parent 465cb98 commit 8f37ccc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -35,6 +35,7 @@ David Diaz
Ederag
Eli Collins
Eugene Yunak
Fabian Poggenhans
Felix Hildén
Fernando L. Pereira
Florian Bruhin
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/2372.feature.rst
@@ -0,0 +1 @@
Add default environment variables (such as http_proxy) regardless of their case to passenv on UNIX -- by :user:`poggenhans`.
3 changes: 2 additions & 1 deletion docs/config.rst
Expand Up @@ -460,7 +460,8 @@ Complete list of settings that you can put into ``testenv*`` sections:
``A`` will pass both ``A`` and ``a``.

Some variables are always passed through to ensure the basic functionality
of standard library functions or tooling like pip:
of standard library functions or tooling like pip.
This is also not case sensitive on all platforms except Windows:

* passed through on all platforms: ``CURL_CA_BUNDLE``, ``PATH``,
``LANG``, ``LANGUAGE``,
Expand Down
4 changes: 4 additions & 0 deletions src/tox/config/__init__.py
Expand Up @@ -809,6 +809,10 @@ def passenv(testenv_config, value):
passenv.add("MSYSTEM") # fixes #429
else:
passenv.add("TMPDIR")

# add non-uppercased variables to passenv if present (only necessary for UNIX)
passenv.update(name for name in os.environ if name.upper() in passenv)

for spec in value:
for name in os.environ:
if fnmatchcase(name.upper(), spec.upper()):
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/config/test_config.py
Expand Up @@ -1494,6 +1494,8 @@ def test_passenv_as_multiline_list(self, newconfig, monkeypatch, plat):
monkeypatch.setenv("A123A", "a")
monkeypatch.setenv("A123B", "b")
monkeypatch.setenv("BX23", "0")
if plat == "linux2":
monkeypatch.setenv("http_proxy", "c")
config = newconfig(
"""
[testenv]
Expand All @@ -1518,6 +1520,7 @@ def test_passenv_as_multiline_list(self, newconfig, monkeypatch, plat):
assert "MSYSTEM" in envconfig.passenv
else:
assert "TMPDIR" in envconfig.passenv
assert "http_proxy" in envconfig.passenv
assert "CURL_CA_BUNDLE" in envconfig.passenv
assert "PATH" in envconfig.passenv
assert "PIP_INDEX_URL" in envconfig.passenv
Expand Down

0 comments on commit 8f37ccc

Please sign in to comment.