-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Test that venvs created in tests are properly isolated #11326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
d3f73ad
to
f47f8f3
Compare
I can make this test fail locally on Ubuntu 20 with Python 3.7, 3.9, 3.10 (from deadsnakes). But it succeeds with the system Python 3.8. That is weird indeed. |
Interesting. I'm extremely glad someone can reproduce it. I was starting to think I was going crazy! |
Correction: after removing the |
And the venv built by the test has a So we have a virtualenv whose python is from a "parent" virtualenv, and the paths of that parent virtualenv leaks in the child virtualenv. That is something I have noticed before in other circumstances and never tried to understand why. I can reproduce this in a ubuntu 20 container: # apt update
# apt install python3 python3-pip python3-venv --no-install-recommends
# pip install --user "virtualenv<20"
# cd /tmp
# python3 -m virtualenv testvenv
# testvenv/bin/python -c "import venv; venv.EnvBuilder().create('/tmp/testvenv-child')"
# ./testvenv-child/bin/python -m site
sys.path = [
'/tmp',
'/tmp/testvenv/lib/python38.zip',
'/tmp/testvenv/lib/python3.8',
'/tmp/testvenv/lib/python3.8/lib-dynload',
'/usr/lib/python3.8',
'/tmp/testvenv/lib/python3.8/site-packages',
]
USER_BASE: '/root/.local' (exists)
USER_SITE: '/root/.local/lib/python3.8/site-packages' (exists)
ENABLE_USER_SITE: False In the result of That does not explain why nox does it, but not always... |
Interesting. I thought "home" (which AIUI corresponds to If this were reproducible in a version of Python created from python.org sources, I'd be tempted to call it a bug, although it might get rejected as the docs for However, I'm 100% sure that the behaviour of "leaking" packages from the base env into the child env is a bug. |
I raised python/cpython#95469 to get the |
Wow, that's weird, given that I thought the parent virtualenv was the one created by nox. Maybe I missed a layer somewhere... But ultimately, I agree, if this is basically #11288, we've already got that in hand. I feel that maybe it's worth retaining this PR, if only to remind us to check the basic assumption that venvs are isolated once #11288 is fixed. But at that point, I'll probably change the test for Thanks for the diagnostic work here - I'd reached a point where I was completely stumped, and I doubt I'd have got to the bottom of it without your help. |
I believe this is because
FWIW, the parent's $ ./testvenv/bin/python -S -c 'import sys; print(sys.base_prefix)'
/tmp/testvenv |
See the discussion in #11320 for context. It appears that virtual environments created via the stdlib
venv
module in tests are not properly isolated. This PR adds a test case to reproduce the issue.