[Zope-CVS] CVS: Packages/Zope2+3 - test.py:1.2
Jeremy Hylton
jeremy at zope.com
Mon Mar 15 12:29:22 EST 2004
Update of /cvs-repository/Packages/Zope2+3
In directory cvs.zope.org:/tmp/cvs-serv28644
Modified Files:
test.py
Log Message:
Report test errors on failures during import or executing
test_suite().
=== Packages/Zope2+3/test.py 1.1.1.1 => 1.2 ===
--- Packages/Zope2+3/test.py:1.1.1.1 Wed Mar 3 16:36:10 2004
+++ Packages/Zope2+3/test.py Mon Mar 15 12:29:21 2004
@@ -199,7 +199,7 @@
self._debug = debug
self._progress = progress
self._progressWithNames = False
- self._count = count
+ self.count = count
self._testtimes = {}
if progress and verbosity == 1:
self.dots = False
@@ -261,9 +261,9 @@
def startTest(self, test):
if self._progress:
self.stream.write("\r%4d" % (self.testsRun + 1))
- if self._count:
- self.stream.write("/%d (%5.1f%%)" % (self._count,
- (self.testsRun + 1) * 100.0 / self._count))
+ if self.count:
+ self.stream.write("/%d (%5.1f%%)" % (self.count,
+ (self.testsRun + 1) * 100.0 / self.count))
if self.showAll:
self.stream.write(": ")
elif self._progressWithNames:
@@ -341,14 +341,20 @@
self._debug = debug
self._progress = progress
self._profile = profile
+ # Create the test result here, so that we can add errors if
+ # the test suite search process has problems. The count
+ # attribute must be set in run(), because we won't know the
+ # count until all test suites have been found.
+ self.result = ImmediateTestResult(
+ self.stream, self.descriptions, self.verbosity, debug=self._debug,
+ progress=self._progress)
def _makeResult(self):
- return ImmediateTestResult(self.stream, self.descriptions,
- self.verbosity, debug=self._debug,
- count=self._count, progress=self._progress)
+ # Needed base class run method.
+ return self.result
def run(self, test):
- self._count = test.countTestCases()
+ self.result.count = test.countTestCases()
if self._profile:
prof = hotshot.Profile("tests_profile.prof")
args = (self, test)
@@ -522,23 +528,42 @@
mod = getattr(mod, part)
return mod
-def get_suite(file):
+class PseudoTestCase:
+ """Minimal test case objects to create error reports.
+
+ If test.py finds something that looks like it should be a test but
+ can't load it or find its test suite, it will report an error
+ using a PseudoTestCase.
+ """
+
+ def __init__(self, name, descr=None):
+ self.name = name
+ self.descr = descr
+
+ def shortDescription(self):
+ return self.descr
+
+ def __str__(self):
+ return "Invalid Test (%s)" % self.name
+
+def get_suite(file, result):
modname = finder.module_from_path(file)
try:
mod = package_import(modname)
except ImportError, err:
- # print traceback
- print "Error importing %s\n%s" % (modname, err)
- traceback.print_exc()
- if debug:
- raise
+ result.addError(PseudoTestCase(modname), sys.exc_info())
return None
try:
suite_func = mod.test_suite
except AttributeError:
- print "No test_suite() in %s" % file
+ result.addError(PseudoTestCase(modname), sys.exc_info())
+ return None
+ try:
+ return suite_func()
+ except:
+ result.addError(PseudoTestCase(modname), sys.exc_info())
return None
- return suite_func()
+
def filter_testcases(s, rx):
new = unittest.TestSuite()
@@ -620,7 +645,7 @@
progress=progress, profile=profile)
suite = unittest.TestSuite()
for file in files:
- s = get_suite(file)
+ s = get_suite(file, runner.result)
# See if the levels match
dolevel = (level == 0) or level >= getattr(s, "level", 0)
if s is not None and dolevel:
More information about the Zope-CVS
mailing list