Module Name
Brad Bollenbach
bbollenbach at home.com
Wed Aug 15 09:18:47 EDT 2001
The Python manual has an example snippet of how to "fake" your own
import.
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 http://www.python.org/doc/current/lib/built-in-funcs.html.
Hans Nowak <hnowak at cuci.nl> wrote in message news:<mailman.997870463.28881.python-list at python.org>...
> >===== Original Message From "Kerim Borchaev" <warkid at storm.ru> =====
>
> >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