-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Virtual environment breaks test_sysconfig
and test_venv
tests on macOS
#103224
Comments
What if you do |
…env` Now running tests through a Python symlink no longer causes `test_upgrade_dependencies` and `test_zippath_from_non_installed_posix` to fail.
@dtrodrigues Both I have opened a PR regarding |
Regarding Although I'm not entirely sure if this is the correct way to fix the test. So before opening the next PR regarding @hroncok Could you please take a look if you have a chance? Here is a patch: diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index b6dbf3d52c..a95e7f4367 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -151,7 +151,7 @@ def test_posix_venv_scheme(self):
# Resolve the paths in prefix
binpath = os.path.join(sys.prefix, binpath)
- incpath = os.path.join(sys.prefix, incpath)
+ incpath = os.path.join(sys.base_prefix, incpath)
libpath = os.path.join(sys.prefix, libpath)
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv'))
@@ -171,7 +171,7 @@ def test_nt_venv_scheme(self):
# Resolve the paths in prefix
binpath = os.path.join(sys.prefix, binpath)
- incpath = os.path.join(sys.prefix, incpath)
+ incpath = os.path.join(sys.base_prefix, incpath)
libpath = os.path.join(sys.prefix, libpath)
self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv')) |
Will do! It has been a while since I wrote that, but I'll try to figure it out. |
The include path is indeed defined via installed_base and the default for insatlled_base is sys.base_prefix, so the diff makes the test pass but arguably makes the test more fragile for potential future posix_venv changes. I suggest instead of "Resolve the paths in prefix" we resolve the paths in "venv/" and then we set vars to a dict similar to the one in Lines 97 to 102 in f513d5c
Something like this (untested): diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index b6dbf3d52cb..1137c2032b9 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -149,17 +149,21 @@ def test_posix_venv_scheme(self):
'python%d.%d' % sys.version_info[:2],
'site-packages')
- # Resolve the paths in prefix
- binpath = os.path.join(sys.prefix, binpath)
- incpath = os.path.join(sys.prefix, incpath)
- libpath = os.path.join(sys.prefix, libpath)
+ # Resolve the paths in an imaginary venv/ directory
+ binpath = os.path.join('venv', binpath)
+ incpath = os.path.join('venv', incpath)
+ libpath = os.path.join('venv', libpath)
- self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv'))
- self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv'))
+ # Mimic the venv module, set all bases to the venv directory
+ bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
+ vars = {base: 'venv' for base in bases}
+
+ self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv', vars=vars))
+ self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv', vars=vars))
# The include directory on POSIX isn't exactly the same as before,
# but it is "within"
- sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv')
+ sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv', vars=vars)
self.assertTrue(sysconfig_includedir.startswith(incpath + os.sep))
def test_nt_venv_scheme(self):
@@ -169,14 +173,19 @@ def test_nt_venv_scheme(self):
incpath = 'Include'
libpath = os.path.join('Lib', 'site-packages')
- # Resolve the paths in prefix
- binpath = os.path.join(sys.prefix, binpath)
- incpath = os.path.join(sys.prefix, incpath)
- libpath = os.path.join(sys.prefix, libpath)
+ # Resolve the paths in an imaginary venv\ directory
+ venv = 'venv'
+ binpath = os.path.join(venv, binpath)
+ incpath = os.path.join(venv, incpath)
+ libpath = os.path.join(venv, libpath)
+
+ # Mimic the venv module, set all bases to the venv directory
+ bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
+ vars = {base: 'venv' for base in bases}
- self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv'))
- self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv'))
- self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv'))
+ self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv', vars=vars))
+ self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv', vars=vars))
+ self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv', vars=vars))
def test_venv_scheme(self):
if sys.platform == 'win32': I think that this should have been done initially and my test was buggy. |
…hen executed through a Python symlink Co-authored-by: Miro Hrončok <miro@hroncok.cz>
To pass tests when executed through a Python symlink. Co-authored-by: Miro Hrončok <miro@hroncok.cz>
This change causes tests to break when configured and run through a prefix:
macOS Logs: ======================================================================
ERROR: test_zippath_from_non_installed_posix (test.test_venv.BasicTest.test_zippath_from_non_installed_posix)
Test that when create venv from non-installed python, the zip path
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/runner/work/1/a/layout/lib/python3.13/test/test_venv.py", line 612, in test_zippath_from_non_installed_posix
subprocess.check_call(cmd, env=child_env)
File "/Users/runner/work/1/a/layout/lib/python3.13/subprocess.py", line 408, in check_call
retcode = call(*popenargs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/runner/work/1/a/layout/lib/python3.13/subprocess.py", line 389, in call
with Popen(*popenargs, **kwargs) as p:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/runner/work/1/a/layout/lib/python3.13/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Users/runner/work/1/a/layout/lib/python3.13/subprocess.py", line 1950, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/test_python_ceck5p2j/tmpv23r1zhj/bin/python3'
======================================================================
FAIL: test_upgrade_dependencies (test.test_venv.BasicTest.test_upgrade_dependencies)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/runner/work/1/a/layout/lib/python3.13/test/test_venv.py", line 236, in test_upgrade_dependencies
builder.upgrade_dependencies(fake_context)
File "/Users/runner/work/1/a/layout/lib/python3.13/venv/__init__.py", line 459, in upgrade_dependencies
self._call_new_python(context, '-m', 'pip', 'install', '--upgrade',
File "/Users/runner/work/1/a/layout/lib/python3.13/venv/__init__.py", line 355, in _call_new_python
subprocess.check_output(args, **kwargs)
File "/Users/runner/work/1/a/layout/lib/python3.13/test/test_venv.py", line 222, in pip_cmd_checker
self.assertEqual(
AssertionError: Lists differ: ['/va[76 chars]ct/bin/python3', '-m', 'pip', 'install', '--upgrade', 'pip'] != ['/va[76 chars]ct/bin/python3.13', '-m', 'pip', 'install', '--upgrade', 'pip']
First differing element 0:
'/var[30 chars]sl6xvm0000gn/T/test_python_ceck5p2j/tmp37gcakct/bin/python3'
'/var[30 chars]sl6xvm0000gn/T/test_python_ceck5p2j/tmp37gcakct/bin/python3.13'
- ['/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/test_python_ceck5p2j/tmp37gcakct/bin/python3',
+ ['/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/test_python_ceck5p2j/tmp37gcakct/bin/python3.13',
? +++
'-m',
'pip',
'install',
'--upgrade',
'pip']
I get the same failure (slightly different paths) on Ubuntu. Any other thoughts on how to solve the original issue? |
Even with #103292 ? |
I'm just running against what's in main, so I don't know yet :) I'll patch it into my repo and have a go |
But it looks like that only affects test_sysconfig, and so won't impact the changes made by #103243 ? |
No idea. The change in PR I linked should fix problems in the test when custom prefix is set. It's long time since it was proposed and I lost all the context. |
Well, it doesn't give me any more failures at least. I think the problem is that Clearly we just need to make the test robust enough for both scenarios, as both are legitimate. I'm not sure what the original problem being solved is though, so the best I can do is try to revert the change. |
FWIW, I fixed this for myself by running tests through I still think we should be able to handle both, but at least it's probably just a test issue. |
#103243 broke some builtbots.
It can be easily reproduced by creating a symlink to Python executable and running tests via the symlink.
Reverting #103243 fixes this issue. I actually first wrote a fix myself, but it turned out to be equivalent to the reversion of #103243. |
… `test_venv` (pythonGH-103243)" This reverts commit 85b0b0c. It broke builtbots.
I've approved the reversion - @artemmukhin perhaps the change needed to be more narrowly applied? If you want to work up a PR we can test with the build-bots first before finalizing it. |
I have no macOS. Can the original issue be reproduced on non-macOS? What exactly the failure report, which lines fail and with what output? |
* main: pythongh-108520: Fix bad fork detection in nested multiprocessing use case (python#108568) pythongh-108590: Revert pythongh-108657 (commit 400a1ce) (python#108686) pythongh-108494: Argument Clinic: Document how to generate code that uses the limited C API (python#108584) Document Python build requirements (python#108646) pythongh-101100: Fix Sphinx warnings in the Logging Cookbook (python#108678) Fix typo in multiprocessing docs (python#108666) pythongh-108669: unittest: Fix documentation for TestResult.collectedDurations (python#108670) pythongh-108590: Fix sqlite3.iterdump for invalid Unicode in TEXT columns (python#108657) Revert "pythongh-103224: Use the realpath of the Python executable in `test_venv` (pythonGH-103243)" (pythonGH-108667) pythongh-106320: Remove private _Py_ForgetReference() (python#108664) Mention Ellipsis pickling in the docs (python#103660) Revert "Use non alternate name for Kyiv (pythonGH-108533)" (pythonGH-108649) pythongh-108278: Deprecate passing the first param of sqlite3.Connection callback APIs by keyword (python#108632) pythongh-108455: peg_generator: install two stubs packages before running mypy (python#108637) pythongh-107801: Improve the accuracy of io.IOBase.seek docs (python#108268)
To pass tests when executed through a Python symlink. Co-authored-by: Miro Hrončok <miro@hroncok.cz>
…03292) To pass tests when executed through a Python symlink. Co-authored-by: Miro Hrončok <miro@hroncok.cz>
Bug report
python -m test
Results in:
TODO
test_sysconfig
gh-103224: Resolve paths properly intest_sysconfig
#103292test_venv
GH-103224: Use the realpath of the Python executable intest_venv
#103243Your environment
main
Linked PRs
test_venv
#103243test_sysconfig
#103292test_venv
(GH-103243)" #108667The text was updated successfully, but these errors were encountered: