[Zope3-checkins] CVS: Zope3 - test.py:1.57

Jeremy Hylton jeremy@zope.com
Fri, 18 Apr 2003 10:06:54 -0400


Update of /cvs-repository/Zope3
In directory cvs.zope.org:/tmp/cvs-serv2352

Modified Files:
	test.py 
Log Message:
Don't import a package unless it matches the test module regex.

The code that searched for test modules matching a particular regex
also imported every package it encountered along the way.  Change the
logic to only import a package if it has a module that matches.  Makes
running individual test modules much faster.


=== Zope3/test.py 1.56 => 1.57 ===
--- Zope3/test.py:1.56	Wed Apr 16 16:51:23 2003
+++ Zope3/test.py	Fri Apr 18 10:06:54 2003
@@ -342,7 +342,8 @@
         if functional:
             config_file = 'ftesting.zcml'
             if not self.inplace:
-                # We chdired into build, so ftesting.zcml is in the parent directory
+                # We chdired into build, so ftesting.zcml is in the
+                # parent directory
                 config_file = os.path.join('..', 'ftesting.zcml')
             print "Parsing %s" % config_file
             from zope.testing.functional import FunctionalTestSetup
@@ -376,6 +377,16 @@
                 return
             print "not a package", dir
             return
+
+        # Put matching files in matches.  If matches is non-empty,
+        # then make sure that the package is importable.
+        matches = []
+        for file in files:
+            if file.startswith('test') and os.path.splitext(file)[-1] == '.py':
+                path = os.path.join(dir, file)
+                if match(rx, path):
+                    matches.append(path)
+
         # ignore tests when the package can't be imported, possibly due to
         # dependency failures.
         pkg = dir[self._plen:].replace(os.sep, '.')
@@ -387,12 +398,8 @@
             if VERBOSE:
                 print "skipping %s because: %s" % (pkg, e)
             return
-
-        for file in files:
-            if file.startswith('test') and os.path.splitext(file)[-1] == '.py':
-                path = os.path.join(dir, file)
-                if match(rx, path):
-                    self.files.append(path)
+        else:
+            self.files.extend(matches)
 
     def module_from_path(self, path):
         """Return the Python package name indicated by the filesystem path."""