Skip to content

Add ability to access env vars that are changed in test-related subprocesses #7082

@duckinator

Description

@duckinator

What'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 #6391 (comment).

Here's @chrahunt's explanation from #6391 (comment):

The basic issue appears to be that changes to APPDATA and LOCALAPPDATA in the environment of the current process do not impact the returned value of ctypes.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 from appdirs.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: #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-lockedOutdated issues that have been locked by automation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions