This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes test_macholib fails if libz is not installed in /usr/lib
Type: Stage: resolved
Components: ctypes Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, nullpex, python-dev, ronaldoussoren
Priority: low Keywords:

Created on 2014-03-29 02:31 by nullpex, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg215107 - (view) Author: Nullpex (nullpex) Date: 2014-03-29 02:31
I'm compiling on a Mac OS X 10.9.2.
Python version 3.4.0.
My libz --prefix is $HOME so the library is in $HOME/lib/
The issue is line 53 of Lib/ctypes/test/test_macholib.py which has /usr/lib/libz.1 hardcoded:

======================================================================
FAIL: test_find (ctypes.test.test_macholib.MachOTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/machados/src/Python-3.4.0/Lib/ctypes/test/test_macholib.py", line 53, in test_find
    self.assertTrue(result.startswith('/usr/lib/libz.1'))
AssertionError: False is not true

I've added a print before the assert command and the library is successfully found:

$ ./python.exe ./Lib/ctypes/test/test_macholib.py
/Users/machados/lib/libz.1.2.8.dylib
F
======================================================================
FAIL: test_find (__main__.MachOTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/machados/src/Python-3.4.0/Lib/ctypes/test/test_macholib.py", line 54, in test_find
    self.assertTrue(result.startswith('/usr/lib/libz.1'))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 1 test in 0.001s

As you can see the library is found in /Users/machados/lib/libz.1.2.8.dylib which is correct.
msg215111 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-03-29 03:30
Thanks for the report.  It seems to me this is a very rare case here: since libz is supplied by OS X, it would be untypical for someone building Python to supply their own version in $HOME/lib.  But, further, the point of the test is not to find the copy of libz that Python was built with, rather it is just to verify that the darwin version of ctypes.find_library() can find system libraries at their well-known locations.  It would be somewhat difficult to set up a test of all of the search paths that are used, emulating the behavior of the system dynamic loader, dyld.  As documented in the code and in the man page for dyld, the relevant search path is DYLD_FALLBACK_LIBRARY_PATH, which is $(HOME)/lib:/usr/local/lib:/lib:/usr/lib.  So the test will unexpectedly find libz in $HOME/lib first, as it did for you.

I was going to assert that you were the first person to ever report running into this issue but, searching a bit, I found Issue1544102 which was never resolved but, thanks to your analysis, I now suspect was another instance with the same root cause.  I guess we could change the test to accept a libz found in $HOME/lib or /usr/local/lib as well.  Or we could just search for a different versioned system library less likely to shadowed in those locations, e.g. one not used in a Python build.
msg215118 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-29 07:10
New changeset e30142fde075 by Ned Deily in branch '2.7':
Issue #21093: Prevent failures of ctypes test_macholib on OS X if a
http://hg.python.org/cpython/rev/e30142fde075

New changeset 831bd1a1cf6c by Ned Deily in branch '3.4':
Issue #21093: Prevent failures of ctypes test_macholib on OS X if a
http://hg.python.org/cpython/rev/831bd1a1cf6c

New changeset 33c4c01404cd by Ned Deily in branch 'default':
Issue #21093: merge from 3.4
http://hg.python.org/cpython/rev/33c4c01404cd
msg215119 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-03-29 07:14
test_macholib has been changed to no longer fail if a local copy of libz is encountered on the dyld search path ($HOME/lib or /usr/local/lib).  Applied for release in 3.5.0, 3.4.1, and 2.7.7.
History
Date User Action Args
2022-04-11 14:58:00adminsetgithub: 65292
2014-03-29 07:14:55ned.deilysetstatus: open -> closed
versions: + Python 2.7
messages: + msg215119

resolution: fixed
stage: needs patch -> resolved
2014-03-29 07:10:23python-devsetnosy: + python-dev
messages: + msg215118
2014-03-29 03:30:46ned.deilysetpriority: normal -> low

type: compile error ->
versions: + Python 3.5
nosy: + ronaldoussoren, ned.deily

messages: + msg215111
stage: needs patch
2014-03-29 02:31:12nullpexcreate