Repository: tox-dev/tox

Issue:
USERPROFILE is not automatically forwarded on Windows
Hi there!

Given the following `tox.ini`:

```ini
[tox]
skipsdist = true

[testenv]
commands =
  python -c 'import os.path; print(os.path.expanduser("~"))'
```

Then, on Windows, this will incorrectly print `~`.

If you add a `passenv` section to forward `USERPROFILE`, then it gives the right output:

```ini
[tox]
skipsdist = true

[testenv]
passenv =
  USERPROFILE
commands =
  python -c 'import os.path; print(os.path.expanduser("~"))'
```

This prints `C:\Users\...` as you would expect.

If I'm not mistaken, I believe `HOME` is forwarded by default on other systems, I would assume `USERPROFILE` should also be forwarded by default on Windows.

I'll gladly work on a patch if you're willing to accept such a contribution!

Discussion:

Patch:
diff --git a/CHANGELOG b/CHANGELOG
index 8bdb5b8d..d0a878c7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@ Not released yet
 
 - #474: Start using setuptools_scm for tag based versioning.
 - #506: With `-a`: do not show additional environments header if there are none
+- #518: Forward `USERPROFILE` by default on Windows.
 
 2.7.0
 -----
diff --git a/tox/config.py b/tox/config.py
index 406cc5de..a1b1cbf6 100755
--- a/tox/config.py
+++ b/tox/config.py
@@ -489,6 +489,7 @@ def tox_addoption(parser):
             passenv.add("COMSPEC")      # needed for distutils cygwincompiler
             passenv.add("TEMP")
             passenv.add("TMP")
+            passenv.add("USERPROFILE")  # needed for `os.path.expanduser()`.
         else:
             passenv.add("TMPDIR")
         for spec in value:


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
index 4eac45e6..5a87159f 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -864,6 +864,7 @@ class TestConfigTestEnv:
             assert "COMSPEC" in envconfig.passenv
             assert "TEMP" in envconfig.passenv
             assert "TMP" in envconfig.passenv
+            assert "USERPROFILE" in envconfig.passenv
         else:
             assert "TMPDIR" in envconfig.passenv
         assert "PATH" in envconfig.passenv