Add ability to access env vars that are changed in test-related subprocesses
See original GitHub issueWhat’s the problem this feature will solve?
While I was working on #6391 to add a pip cache
command, I ran into an issue where environment variables are changed in subprocesses started when a test uses script.pip(...)
and similar, but I have no simple way to get this information. See https://github.com/pypa/pip/pull/6391#issuecomment-511151106.
Here’s @chrahunt’s explanation from https://github.com/pypa/pip/pull/6391#issuecomment-511151106:
The basic issue appears to be that changes to
APPDATA
andLOCALAPPDATA
in the environment of the current process do not impact the returned value ofctypes.windll.shell32.SHGetFolderPathW
. Only for sub-processes.One option could be to take the current value of
os.environ['LOCALAPPDATA']
and append\pip\Cache
to it, duplicating the logic fromappdirs.user_cache_dir
.Another option could be to get the cache dir from a sub-process itself, like
script.run('python', '-c', 'from pip._internal.locations import USER_CACHE_DIR; print(USER_CACHE_DIR)
. This seems like more of a hack, but does avoid the duplication.In either case, it may be good to make it a property of
PipTestEnvironment
so it’s accessible from the required tests or any others that might need the cache directory.
Describe the solution you’d like
TBD — I’m not sure what approach would be best, and was hoping to get some input on that.
Additional context
PR where this problem came to my attention: https://github.com/pypa/pip/pull/6391
Code where the environment variables are changed: https://github.com/pypa/pip/blob/master/tests/conftest.py#L98-L166
File where PipTestEnvironment
, a potential location for tracking this information, is defined: https://github.com/pypa/pip/blob/master/tests/lib/__init__.py
cc @chrahunt
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Let’s delay that – I’m fairly averse to over-engineering things so I don’t think there’s much point in doing this eagerly.
I did that. 😉