Module Name

Brad Bollenbach bbollenbach at
Wed Aug 15 15:18:47 CEST 2001

The Python manual has an example snippet of how to "fake" your own

import string

def my_import(name):
    mod = __import__(name)
    components = string.split(name, '.')
    for comp in components[1:]:
        mod = getattr(mod, comp)
    return mod

__import__ is a builtin function that Python's import statement calls.
The for loop ensures that if you're importing a module from a package
(ie. the "z" in x.y.z) that the "mod" variable will actually hold the
module, and not the package.

For more, see

Hans Nowak <hnowak at> wrote in message news:<mailman.997870463.28881.python-list at>...
> >===== Original Message From "Kerim Borchaev" <warkid at> =====
> >so the question is : How can I implement addModule?
> >def addModule(suite, module):
> >    __import__(module)
> >    suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(module))
> >
> >doesnt execute any test.  loadTestsFromModule doesn't work - and I
> >can't understand why...
> I have no experience with unittest, but I think that
>   module = __import__(module)
> should work. I figure loadTestsFroModule needs a module object, rather than a 
> string, which is what it gets now.
> HTH,
> --Hans Nowak

More information about the Python-list mailing list