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
test_loading.py - false positive result for "def test_find" when find_library() is not functional or the (shared) library does not exist #72463
Comments
in Lib/ctypes/test/test_loading.py there is the following test def test_find(self):
for name in ("c", "m"):
lib = find_library(name)
if lib:
cdll.LoadLibrary(lib)
CDLL(lib)
As far as library names to look for I suggest switching "m" to "ssl" - as something that should be everywhere. And the test should be something more like: self.assertEqual(lib not None) OR is the test actually testing LoadLibrary and CDLL (as well) Back to my humble opinion: assuming the real test is to test LoadLibrary and CDLL by accepting None as a valid result from find_library - false POSITIVE is the result when find_library() is not working. |
The assert to be added is much more simple: i.e., self.assertTrue(lib) And then you get something like: root@x064:[/data/prj/python/python-3.6.0.177/Lib/ctypes/test]../../../python -m unittest test_loading.py Traceback (most recent call last):
File "/data/prj/python/python-3.6.0.177/Lib/ctypes/test/test_loading.py", line 55, in test_find
self.assertTrue(lib)
AssertionError: None is not true Ran 7 tests in 0.126s FAILED (failures=1, skipped=5) |
The purpose of the test seems to be to check that finding and loading works for widely-available libraries. However I suspect find_library("c") can fail on other platforms as well. Presumably that is why there is the special case for Cygwin at the top of the file. Open SSL is also widely available, but not universal. I think it is even possible to build Python without SSL support, and the tests should not fail in this case. Perhaps it would be okay to remove "m" and just run the test on find_library("c"). If so, we can adjust the test to call self.skipTest("C library not found"), which will warn that the test could not be run. |
Actually, what may be needed are more "@Skip" blocks - as ctypes has always been platform dependent. OR - have a counter or boolean that starts as zero or false and increase each time find_library() returns a value - and the test fails if the counter is still zero, or boolean is still false. Further, perhaps a separate test_load() that is platform specific - with the correct - read expected - result from find_library(). I say expected because python has always been testing for libc.so.6 while I see in cloud-init that that are calls hard-coded to CDLL("libc.so.7") - but maybe that is something specific for Canonical aka ubuntu. However, it seems that expecting libc.so.6 to ALWAYS be present is not safe. FYI: michael@x071:[/data/prj/python/cloud-init]grep CDLL cloud-init-0*/cloudinit/*.py |
Is this suitable? def test_find(self):
# to track that at least one call to find_library() found something
found = false
for name in ("c", "m"):
lib = find_library(name)
if lib:
found = true
cdll.LoadLibrary(lib)
CDLL(lib)
# test is FAILED if nothing was found
self.assertTrue(found) |
ok - false needs to be False and true needs to be True seemed so simple. Sigh. |
Other tests in this file skip the test if libc_name is None. So I think it would make more sense to skip the test rather than fail in test_find(). I.e. if not found:
self.skipTest("Could not find c and m libraries") If you are confident that find_library() will always find libc on AIX, perhaps you can suggest an extra test (or add to an existing test), to first check for the AIX platform, and only then fail if find_library() returned None. |
On 01-Oct-16 05:57, Martin Panter wrote:
And, bos.rte.libc cannot be uninstalled: SELECTED FILESETS: The following is a list of filesets that you asked to
NON-DEINSTALLABLE DEPENDENTS: The following filesets depend upon one or
64-bit... I gave up counting the number of dependents that "officially" are I'll make a different test (skip if not aix) that find_library("c") must
|
This is something from long long ago - time to get it completed. The (remaining) issue is: "c" and "m" may not be shared libraries - so nothing is ever found and the test is "skipped" but reports itself as PASSED. The original issue (fixed for AIX in Python3.7) would be if find_library itself is broken and always returns NULL/None. Again, the tests says "PASSED" when actually it was skipped. Following this - Martin's suggestion seems a viable solution. |
Concur. Also you can add "ssl" to the list of tested names if both "c" and "m" fail on AIX. |
Sure. Probably have to rebase first. |
…skipped (pythonGH-18312) (cherry picked from commit 04d1000) Co-authored-by: Michael Felt <aixtools@users.noreply.github.com>
…skipped (pythonGH-18312) (cherry picked from commit 04d1000) Co-authored-by: Michael Felt <aixtools@users.noreply.github.com>
Lib/ctypes/test_loading.py
so thattest_find
reports skipped #18312Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: