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.

Author vstinner
Recipients pablogsal, sobolevn, vstinner
Date 2021-09-07.19:25:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1631042737.52.0.646534325927.issue45128@roundup.psfhosted.org>
In-reply-to
Content
I'm not sure if unittest.mock code to import the module is reliable: see bpo-39551. It imports "multiprocessing", use getattr() to get multiprocessing.shared_memory. If getattr() fails with AttributeError, it tries to import "mulitprocessing.shared_memory", and then tries again the same getattr() on the previously imported "multiprocessing" module.

I'm curious if this change works around the issue:

diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index c6067151de..1e3a8277ca 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -1238,7 +1238,7 @@ def _dot_lookup(thing, comp, import_path):
     try:
         return getattr(thing, comp)
     except AttributeError:
-        __import__(import_path)
+        thing = __import__(import_path)
         return getattr(thing, comp)
History
Date User Action Args
2021-09-07 19:25:37vstinnersetrecipients: + vstinner, pablogsal, sobolevn
2021-09-07 19:25:37vstinnersetmessageid: <1631042737.52.0.646534325927.issue45128@roundup.psfhosted.org>
2021-09-07 19:25:37vstinnerlinkissue45128 messages
2021-09-07 19:25:37vstinnercreate