Skip to content

Commit

Permalink
Passenv: Include default env variables regardless of their case on UN…
Browse files Browse the repository at this point in the history
…IX (#2378)

Co-authored-by: Fabian Poggenhans <fabian.poggenhans@daimler.com>
  • Loading branch information
poggenhans and Fabian Poggenhans committed Mar 18, 2022
1 parent 465cb98 commit 31dc5b1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
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
7 changes: 6 additions & 1 deletion 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,9 @@ def test_passenv_as_multiline_list(self, newconfig, monkeypatch, plat):
assert "MSYSTEM" in envconfig.passenv
else:
assert "TMPDIR" in envconfig.passenv
if sys.platform != "win32":
# this cannot be emulated on win - it doesn't support lowercase env vars
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 Expand Up @@ -3575,7 +3580,7 @@ def test_config_via_pyproject_legacy(initproj):
initproj(
"config_via_pyproject_legacy-0.5",
filedefs={
"pyproject.toml": u'''
"pyproject.toml": '''
[project]
description = "Factory ⸻ A code generator 🏭"
authors = [{name = "Łukasz Langa"}]
Expand Down

0 comments on commit 31dc5b1

Please sign in to comment.