Making module content available in parent module

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Tue Nov 23 05:36:05 EST 2010


Hi!

Note up front: I'm using Python2.6 still, I guess with 2.7 test discovery, I
could get better results easier, right?

Now, my problem is I have a directory containing test scripts which I all
want to run. I used to run them individually and manually, but want to
avoid this overhead in the future.

 tests/
   foo.py # defines TestFoo1 and TestFoo2
   bar.py # defines TestBar1 and TestBar2

What I would like to do now is this:

 from tests import *
 unittest.main()

In other words, import all test files and run them. This does import them,
but it turns out that I end up with modules foo and bar, and the unittests
inside those are not found.

Am I approaching the test loading the wrong way?


Cheers!

Uli


PS: I've been trying a few things here, and stumbled across another thing
that could provide a solution. I can "from tests import *", but then all
these modules will pollute my namespace. I can "import tests", but then
neither of the submodules will be in "tests". I tried "import tests.*", but
that doesn't work. Is there no way to import a whole package but with its
namespace?

-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list