[Zope3-checkins] CVS: Zope3 - test.py:1.21
Barry Warsaw
barry@wooz.org
Thu, 19 Dec 2002 12:19:32 -0500
Update of /cvs-repository/Zope3
In directory cvs.zope.org:/tmp/cvs-serv32631
Modified Files:
test.py
Log Message:
Moderately ugly hack to de-centralize skipping some tests when
dependencies fail, e.g. don't run the BDBStorage tests if the bsddb3
package isn't available.
Specifically, find_tests() passes the base path to TestFileFinder
constructor. Its .visit() method tries to import each tests package
and if that fails with a RuntimeError don't include that package's
tests.
=== Zope3/test.py 1.20 => 1.21 ===
--- Zope3/test.py:1.20 Wed Dec 11 18:42:58 2002
+++ Zope3/test.py Thu Dec 19 12:19:31 2002
@@ -112,7 +112,7 @@
import traceback
import unittest
import linecache
-from os.path import join
+from os.path import join, commonprefix
from distutils.util import get_platform
@@ -242,20 +242,31 @@
return re.search(rx, s) is not None
class TestFileFinder:
- def __init__(self):
+ def __init__(self, prefix):
self.files = []
+ self.prefix = prefix
def visit(self, rx, dir, files):
- if dir[-5:] != "tests":
+ if not dir.endswith('tests'):
return
# ignore tests that aren't in packages
if not "__init__.py" in files:
if not files or files == ['CVS']:
return
-
print "not a package", dir
return
+ # ignore tests when the package can't be imported, possibly due to
+ # dependency failures.
+ pkg = dir[len(self.prefix)+1:].replace('/', '.')
+ try:
+ __import__(pkg)
+ # We specifically do not want to catch ImportError since that's useful
+ # information to know when running the tests.
+ except RuntimeError, e:
+ print 'skipping', pkg, 'because:', e
+ return
+
for file in files:
if file[:4] == "test" and file[-3:] == ".py":
path = join(dir, file)
@@ -263,8 +274,9 @@
self.files.append(path)
def find_tests(rx):
- finder = TestFileFinder()
- os.path.walk(join('lib','python'), finder.visit, rx)
+ prefix = join('lib', 'python')
+ finder = TestFileFinder(prefix)
+ os.path.walk(prefix, finder.visit, rx)
return finder.files
def package_import(modname):