This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jaraco
Recipients Anthony Sottile, blueyed, eryksun, jaraco, lazka, miss-islington, paul.moore, steve.dower, tim.golden, zach.ware
Date 2020-05-16.17:18:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1589649531.39.0.618304534028.issue36264@roundup.psfhosted.org>
In-reply-to
Content
> I thought it might be useful for testing purposes if os.path (i.e. ntpath and posixpath) had a way to set the home directory that it uses in way that wouldn't affect other libraries and child processes.

I was thinking about this, and I'd argue that in the general case, you _want_ to be able to set the home directory in a way that affects child processes. If you care enough to try to isolate the behavior from the user-local state, you probably want other libraries and child processes to honor that isolation.

This argument extends to there being a (preferably one) way override a home directory that's honored by tools and processes of all flavors (e.g. overriding USERPROFILE has no effect on git commands in a subprocess).

I agree it may prove useful not to affect the global and subprocess state if possible, but I'd argue in that case, you could probably just patch the library under test directly.

These processes patching $HOME really are attempting to suppress the user's local state (or simulate a specific state).

> Not for me in PowerShell 5 and 7:

Weird. You're right, I get the same thing for test-path. And indeed it's not set in the Python process.

PS C:\WINDOWS\system32> test-path env:home
False
PS C:\WINDOWS\system32> python -c "import os; print(os.environ.get('HOME'))"
None

But strangely, $HOME seems to have some effect.

PS C:\WINDOWS\system32> echo $HOME                                                                                      C:\Users\jaraco
PS C:\WINDOWS\system32> cd $HOME
PS C:\Users\jaraco>

Do you know what that's about?

I found a couple [Powershell users that seem to think setting $HOME is something you would want to do](https://stackoverflow.com/questions/32109375/in-powershell-how-do-i-set-home-variable-before-running-a-script).

And [this Powershell documentation](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7#environment-variables-that-store-preferences) makes reference to $HOME.

I see. Powershell defines $HOME as an [Automatic Variable](https://ss64.com/ps/syntax-automatic-variables.html) internally but doesn't expose it as an environment variable.
History
Date User Action Args
2020-05-16 17:18:51jaracosetrecipients: + jaraco, paul.moore, blueyed, tim.golden, zach.ware, eryksun, steve.dower, lazka, Anthony Sottile, miss-islington
2020-05-16 17:18:51jaracosetmessageid: <1589649531.39.0.618304534028.issue36264@roundup.psfhosted.org>
2020-05-16 17:18:51jaracolinkissue36264 messages
2020-05-16 17:18:51jaracocreate