diff MoinMoin/_tests/__init__.py @ 76:df348d27f1fc

fix bogus error handling in _tests and wikitest Import errors in test_modules were hidden by Python unittest framework, and displayed as bogus AttributeError. Fixed by using more robust way to import test modules. Fix also error handling in wikitest, which hide import error inside a test module as bogus "Tests are not available". imported from: moin--main--1.5--patch-78
author Nir Soffer <nirs@freeshell.org>
date Tue, 04 Oct 2005 02:21:07 +0000
parents 77665d8e2254
children 3bf0b6c09275
line wrap: on
line diff
--- a/MoinMoin/_tests/__init__.py	Mon Oct 03 22:59:54 2005 +0000
+++ b/MoinMoin/_tests/__init__.py	Tue Oct 04 02:21:07 2005 +0000
@@ -132,6 +132,19 @@
     def loadTestsFromTestCase(self, testCaseClass):
         testCaseClass.request = self.request
         return TestLoader.loadTestsFromTestCase(self, testCaseClass)        
+        
+    def loadTestsFromModuleNames(self, names):
+        """ Load tests from qualified module names, eg. a.b.c
+        
+        loadTestsFromNames is broken, hiding ImportErrros in test
+        modules. This method is less flexsible but works correctly.
+        """
+        names = ['%s.%s' % (__name__, name) for name in names]
+        suites = []
+        for name in names:
+            module = __import__(name, globals(), {}, ['dummy'])
+            suites.append(self.loadTestsFromModule(module))    
+        return self.suiteClass(suites)
 
 
 def makeSuite(request, names=None):
@@ -146,12 +159,11 @@
     if not names:
         from MoinMoin.util.pysupport import getPackageModules
         names = getPackageModules(__file__)
-        names = ['%s.%s' % (__name__, name) for name in names
-                 if name.startswith('test_')]
+        names = [name for name in names if name.startswith('test_')]
         caseInsensitiveCompare = lambda a, b: cmp(a.lower(), b.lower())
         names.sort(caseInsensitiveCompare)
-    loader = MoinTestLoader(request)
-    return loader.loadTestsFromNames(names)
+    
+    return MoinTestLoader(request).loadTestsFromModuleNames(names)
 
 
 def run(request=None, names=None):