changeset 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 e11a18329e13
children 7445f044ccac
files MoinMoin/_tests/__init__.py MoinMoin/wikitest.py
diffstat 2 files changed, 22 insertions(+), 6 deletions(-) [+]
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):
--- a/MoinMoin/wikitest.py	Mon Oct 03 22:59:54 2005 +0000
+++ b/MoinMoin/wikitest.py	Tue Oct 04 02:21:07 2005 +0000
@@ -86,10 +86,14 @@
     if config.use_threads:
         request.write("    *** The unit tests are disabled when using multi "
                       "threading ***")
-    else:       
+    else:
+        # TODO: do we need to hide the error when _tests can't be
+        # imported? It might make it hard to debug the tests package
+        # itself.
         try:    
             from MoinMoin import _tests
-            _tests.run(request)
         except ImportError:
             request.write("    *** The unit tests are not available ***")
+        else:
+            _tests.run(request)