Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Importing a package and looping through modules in the package (http://www.velocityreviews.com/forums/t328123-importing-a-package-and-looping-through-modules-in-the-package.html)

Dave 02-10-2004 03:29 AM

Importing a package and looping through modules in the package
 
Hi Everyone,

I am trying to import a package and then loop through the modules
inside the package, but I'm running to a problem. Basically:
-----
I have a package called
regression.changepassword.unittests which contains test modules.
---
In a test agent module (called agent.a), I do the following:

from regression.changepassword.unittests import *
utilities.runTests("regression.changepassword.unit tests.")
----
in the utilities.runTests, I do the following:
for id in sys.modules.keys():
if id.startswith(testtype) and sys.modules[id] != None:
print "module id is: " + `id`
---------------------------------------------------
However, the loop is never executed since it seems the list of modules
in regression.changepassword.unittests is never added to the
sys.modules. If I import the tests one by one as the follwing:

from regression.changepassword.unittests import CPWD_2
from regression.changepassword.unittests import CPWD_3

Then the program works and loops through the test modules correctly.
Am I doing something wrong? Or that is how Python works and I have to
import modules one by one. I appreciate any help that you can offer
me and thanks for your time ( I apologize if my message is too long).

Thanks,
Bardia

Rich Krauter 02-10-2004 04:39 AM

Re: Importing a package and looping through modules in the package
 
On Mon, 2004-02-09 at 22:29, Dave wrote:
> Hi Everyone,
>
> I am trying to import a package and then loop through the modules
> inside the package, but I'm running to a problem. Basically:
> -----
> I have a package called
> regression.changepassword.unittests which contains test modules.
> ---
> In a test agent module (called agent.a), I do the following:
>
> from regression.changepassword.unittests import *
> utilities.runTests("regression.changepassword.unit tests.")



Do you have __all__ defined in your __init__.py in
regression.changepassword.unittests?

This part of the tutorial might help:
http://www.python.org/doc/current/tu...00000000000000

Rich



Dave 02-10-2004 08:14 PM

Re: Importing a package and looping through modules in the package
 
Rich Krauter <rmkrauter@yahoo.com> wrote in message news:<mailman.1397.1076388282.12720.python-list@python.org>...
> On Mon, 2004-02-09 at 22:29, Dave wrote:
> > Hi Everyone,
> >
> > I am trying to import a package and then loop through the modules
> > inside the package, but I'm running to a problem. Basically:
> > -----
> > I have a package called
> > regression.changepassword.unittests which contains test modules.
> > ---
> > In a test agent module (called agent.a), I do the following:
> >
> > from regression.changepassword.unittests import *
> > utilities.runTests("regression.changepassword.unit tests.")

>
>
> Do you have __all__ defined in your __init__.py in
> regression.changepassword.unittests?
>
> This part of the tutorial might help:
> http://www.python.org/doc/current/tu...00000000000000
>
> Rich


Hi Rich,

Thanks for your response. That was exactly what the problem was. I
should have gone through the tutorial more carefully :).

Thanks,
Bardia


All times are GMT. The time now is 01:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.