[Zope-Checkins] CVS: Zope3/lib/python/Zope/Testing - Builder.py:1.1.4.6
Fred L. Drake, Jr.
fdrake@acm.org
Mon, 4 Feb 2002 10:38:03 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Testing
In directory cvs.zope.org:/tmp/cvs-serv2888/Zope/Testing
Modified Files:
Tag: Zope-3x-branch
Builder.py
Log Message:
Clean up the code that actually imports and loads tests. Not only does it
do less work now (so finding tests is just a little bit faster), it reports
ImportError warnings, which was what we wanted all along.
Note that there *are* two warnings that show up now (for Zope 3x); I will
leave it to others to fix these. ;)
=== Zope3/lib/python/Zope/Testing/Builder.py 1.1.4.5 => 1.1.4.6 ===
self._root_dir = root_dir
self._root_dir_len = len( root_dir.split( os.sep ) )
- self._candiates = []
+ self._candidates = []
self._cant_load = []
self._maybe_cant_load = {}
@@ -96,6 +96,12 @@
header, body = self._formatException(candidate, msg)
self._maybe_cant_load[candidate] = (header, body)
+ def _do_import( self, module ):
+ mod = __import__(module)
+ for name in module.split('.')[1:]:
+ mod = getattr(mod, name)
+ return mod
+
def _buildSuite( self ):
"""
Build a suite from our candidate modules.
@@ -109,24 +115,27 @@
continue
try:
- suite.addTest( self.loadTestsFromName( '%s.test_suite'
- % candidate ) )
- self._loaded.append( '%s (test_suite)' % candidate )
+ mod = self._do_import(candidate)
+ except ImportError:
+ tb = ''.join(traceback.format_exception(*sys.exc_info()))
+ self._cant_load.append(("Failed to import " + candidate, tb))
+ continue
+
+ if hasattr(mod, "test_suite"):
+ suite.addTest(mod.test_suite())
continue
- except Exception, msg:
- self._deferLoadFailure(candidate, msg)
try:
- suite.addTest( self.loadTestsFromName( candidate ) )
- self._loaded.append( '%s (implicit)' % candidate )
+ suite.addTest(self.loadTestsFromModule(mod))
except Exception, msg:
if self._maybe_cant_load.get(candidate):
self._cant_load.append(self._maybe_cant_load[candidate])
- self._recordLoadFailure( '%s (implicit)' % candidate, msg )
+ self._recordLoadFailure('%s (implicit)' % candidate, msg)
+ else:
+ self._loaded.append( '%s (implicit)' % candidate )
return suite
def _loadTestsFromPath( self, path=None ):
- self._candidates = []
if path is None:
path = self._root_dir
os.path.walk( path, self._visit, None )