question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 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 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: 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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pradyunsgcommented, Sep 27, 2019

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.

0reactions
pradyunsgcommented, Sep 28, 2019

I did that. 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python subprocess/Popen with a modified environment
The env parameter accepts a dictionary. You can simply take os.environ, add a key (your desired variable) ...
Read more >
Environment variables to configure the AWS CLI
Environment variables provide another way to specify configuration options and ... Specifies an AWS access key associated with an IAM user or role....
Read more >
How to Set Environment Variables in Linux - phoenixNAP
Set an environment variable in Linux by following this short tutorial. Learn how to view and manage a list of environment variables.
Read more >
How To - Linux Set Environment Variables Command - nixCraft
Explains how to set, view and use Linux environment variables using ... The env command runs a Linux command with a modified environment....
Read more >
How To Read and Set Environmental and Shell Variables on ...
The environment provides a medium through which the shell process can get or set settings and, in turn, pass these on to its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found