From 8f37cccc11ca8f1a9f620515a60fbf8ddfd8baaf Mon Sep 17 00:00:00 2001 From: Fabian Poggenhans Date: Fri, 11 Mar 2022 12:55:09 +0100 Subject: [PATCH] Passenv: Include default env variables regardless of their case on UNIX 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 --- CONTRIBUTORS | 1 + docs/changelog/2372.feature.rst | 1 + docs/config.rst | 3 ++- src/tox/config/__init__.py | 4 ++++ tests/unit/config/test_config.py | 3 +++ 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/2372.feature.rst diff --git a/CONTRIBUTORS b/CONTRIBUTORS index ca325a320e..f3fc340748 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -35,6 +35,7 @@ David Diaz Ederag Eli Collins Eugene Yunak +Fabian Poggenhans Felix Hildén Fernando L. Pereira Florian Bruhin diff --git a/docs/changelog/2372.feature.rst b/docs/changelog/2372.feature.rst new file mode 100644 index 0000000000..470dbc5f88 --- /dev/null +++ b/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`. diff --git a/docs/config.rst b/docs/config.rst index 8f277ffe52..c579733ebd 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -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``, diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 10acbe12ac..b155fd1cfb 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -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()): diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index d6ff0aba48..4e1b232cd3 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -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] @@ -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