[Zope-Coders] __import__ misery
Guido van Rossum
guido@python.org
Wed, 23 Jan 2002 10:36:20 -0500
> I thought about tidying up CMFCore/tests/test_all.py which currently
> contains a load of duplicate and what should be unnecessary code.
>
> However, I can't do it in the way I'd like 'cos __import__ is being
> unhelpful...
>
> In test_all.py, the following works fine:
> import test_ContentTypeRegistry
>
> But the following barfs:
> __import__('test_ContentTypeRegistry')
>
> Traceback (most recent call last):
> File "E:\Zope\cmf_dev\Products\all_cmf_tests.py", line 4, in ?
> from Products.CMFCore.tests import test_all
> File "E:\Zope\cmf_dev\Products\CMFCore\tests\test_all.py", line 5, in ?
> __import__('test_ContentTypeRegistry')
> ImportError: No module named test_ContentTypeRegistry
Could it be that this is importing a sibling module in a package? You
have to pass your globals and locals to __import__ so it knows from
which package you are making the call. See docs for __import__.
--Guido van Rossum (home page: http://www.python.org/~guido/)