Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passenv: Include default env variables regardless of their case on UNIX #2378

Merged
merged 1 commit into from Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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