summaryrefslogtreecommitdiff
path: root/test/package_unittest.py
diff options
context:
space:
mode:
authorcben <cben@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2004-07-25 01:45:27 +0000
committercben <cben@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2004-07-25 01:45:27 +0000
commit2384d0cf6cd5f596511784ff8b54c8ae1e57e8fa (patch)
tree339bcb037dfdb31353dc089a3d93a81c1a0df434 /test/package_unittest.py
parent253d5324a1754ddda972807b0e2ff6303c3dbef4 (diff)
downloaddocutils-2384d0cf6cd5f596511784ff8b54c8ae1e57e8fa.tar.gz
Allow the test suite to survive unimportable test modules.
Notably, this fixes a crash on importing `moduleparser` under Python 2.1 from ``test/test_readers/test_python/test_functions.py``. (This shouldn't happen anyway, added to BUGS.txt) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2449 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'test/package_unittest.py')
-rw-r--r--test/package_unittest.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/test/package_unittest.py b/test/package_unittest.py
index 019d6fb38..135b54f47 100644
--- a/test/package_unittest.py
+++ b/test/package_unittest.py
@@ -99,25 +99,29 @@ def loadTestModules(path, name='', packages=None):
for mod in testModules:
if debug:
print >>sys.stderr, "importing %s" % mod
- module = import_module(mod)
- # if there's a suite defined, incorporate its contents
try:
- suite = getattr(module, 'suite')
- except AttributeError:
- # Look for individual tests
- moduleTests = testLoader.loadTestsFromModule(module)
- # unittest.TestSuite.addTests() doesn't work as advertised,
- # as it can't load tests from another TestSuite, so we have
- # to cheat:
- testSuite.addTest(moduleTests)
- continue
- if type(suite) == types.FunctionType:
- testSuite.addTest(suite())
- elif type(suite) == types.InstanceType \
- and isinstance(suite, unittest.TestSuite):
- testSuite.addTest(suite)
+ module = import_module(mod)
+ except ImportError:
+ print >>sys.stderr, "ERROR: Can't import %s, skipping its tests!" % mod
else:
- raise AssertionError, "don't understand suite (%s)" % mod
+ # if there's a suite defined, incorporate its contents
+ try:
+ suite = getattr(module, 'suite')
+ except AttributeError:
+ # Look for individual tests
+ moduleTests = testLoader.loadTestsFromModule(module)
+ # unittest.TestSuite.addTests() doesn't work as advertised,
+ # as it can't load tests from another TestSuite, so we have
+ # to cheat:
+ testSuite.addTest(moduleTests)
+ continue
+ if type(suite) == types.FunctionType:
+ testSuite.addTest(suite())
+ elif type(suite) == types.InstanceType \
+ and isinstance(suite, unittest.TestSuite):
+ testSuite.addTest(suite)
+ else:
+ raise AssertionError, "don't understand suite (%s)" % mod
sys.path.pop(0)
return testSuite