From 05ea706cebe6d291556b685de23fb35014d5dbb5 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 10 Jan 2007 18:46:35 +0000 Subject: Fix module loading. svn path=/main/trunk/; revision=5532 --- tests/__init__.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 71d699770..2808ed5a4 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -3,19 +3,27 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -import unittest +import os, unittest def main(): - testDirs = ["portage/", "portage_util/"] + testDirs = ["portage", "portage_util"] suite = unittest.TestSuite() - for dir in testDirs: - suite.addTests(getTests(dir)) + basedir = os.path.dirname(__file__) + for mydir in testDirs: + suite.addTests(getTests(os.path.join(basedir, mydir))) return unittest.TextTestRunner(verbosity=2).run(suite) +def my_import(name): + mod = __import__(name) + components = name.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + return mod + def getTests( path ): """ @@ -27,14 +35,14 @@ def getTests( path ): import os files = os.listdir( path ) files = [ f[:-3] for f in files if f.startswith("test_") and f.endswith(".py") ] - + parent_module = ".".join(("tests", os.path.basename(path))) result = [] - for file in files: + for mymodule in files: try: # Make the trailing / a . for module importing - path2 = path[:-1] + "." + file - mod = __import__( path2, globals(), locals(), [path[-1]]) + modname = ".".join((parent_module, mymodule)) + mod = my_import(modname) result.append( unittest.TestLoader().loadTestsFromModule(mod) ) except ImportError: - pass + raise return result -- cgit v1.2.3-1-g7c22