]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-123930: Correct test of attribute failure to account for iOS (GH-125959...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 25 Oct 2024 07:42:20 +0000 (09:42 +0200)
committerGitHub <noreply@github.com>
Fri, 25 Oct 2024 07:42:20 +0000 (07:42 +0000)
gh-123930: Correct test of attribute failure to account for iOS (GH-125959)

Update a test of importing attributes from binary modules to account for iOS conditions.
(cherry picked from commit 75401febc91a449cc4f4391d663e9a96ce91bb6c)

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Lib/test/test_import/__init__.py

index fac5265f1758da49d11dc6bbd95573d3af6bb6d3..3f71a2bf3d9c39da7dffc70bd0ed619fdd2328bb 100644 (file)
@@ -389,10 +389,14 @@ class ImportTests(unittest.TestCase):
             from _testcapi import i_dont_exist
         self.assertEqual(cm.exception.name, '_testcapi')
         if hasattr(_testcapi, "__file__"):
-            self.assertEqual(cm.exception.path, _testcapi.__file__)
+            # The path on the exception is strictly the spec origin, not the
+            # module's __file__. For most cases, these are the same; but on
+            # iOS, the Framework relocation process results in the exception
+            # being raised from the spec location.
+            self.assertEqual(cm.exception.path, _testcapi.__spec__.origin)
             self.assertRegex(
                 str(cm.exception),
-                r"cannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|fwork|pyd)\)"
+                r"cannot import name 'i_dont_exist' from '_testcapi' \(.*(\.(so|pyd))?\)"
             )
         else:
             self.assertEqual(