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 chris.jerdonek
Recipients alexgarel, chris.jerdonek, michael.foord, r.david.murray, rbcollins, slmnhq
Date 2012-06-03.03:23:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Thanks.  It looks like the issue with the latest patch is caused by side effects of calling importlib.import_module().

Working from the patch, I got it to the point where inserting the following four lines somewhere in the code--


caused the exception raised by the following line--

    module = importlib.import_module('package_foo2.subpackage.no_exist')

to change from this--

  File "<frozen importlib._bootstrap>", line 1250, in _find_and_load_unlocked
ImportError: No module named 'package_foo2.subpackage.no_exist'

to this--

  File "..../Lib/importlib/", line 1257, in _find_and_load_unlocked
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'package_foo2'

It looks like this issue is cropping up in the tests because the test code dynamically adds packages to directories that importlib may already have examined.

In the reduced test case I was creating to examine the issue, I found that inserting a call to importlib.invalidate_caches() at an appropriate location resolved the issue.

Should loadTestsFromName() call importlib.invalidate_caches() in the new patch implementation, or should the test code be aware of that aspect of loadTestsFromName()'s behavior and be adjusted accordingly (e.g. by creating the dynamically-added packages in more isolated directories)?  For backwards compatibility reasons, how does loadTestsFromName() currently behave in this regard (i.e. does importlib.import_module() behave the same as __import__ with respect to caching)?
Date User Action Args
2012-06-03 03:23:50chris.jerdoneksetrecipients: + chris.jerdonek, rbcollins, r.david.murray, michael.foord, slmnhq, alexgarel
2012-06-03 03:23:50chris.jerdoneksetmessageid: <>
2012-06-03 03:23:50chris.jerdoneklinkissue7559 messages
2012-06-03 03:23:48chris.jerdonekcreate