[issue45128] test_multiprocessing fails sporadically on the release artifacts

STINNER Victor report at bugs.python.org
Tue Sep 7 15:25:37 EDT 2021


STINNER Victor <vstinner at python.org> added the comment:

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)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45128>
_______________________________________


More information about the Python-bugs-list mailing list