summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-03-21 00:53:39 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-03-21 00:53:39 (GMT)
commit73dbe0461986208564f64e80a7b79264a6a38368 (patch)
tree58235809668fdad075a0731a2af197d0f3486b09 /Lib/unittest
parent134fb10408d3f710c401c73443781a39c0c1a7ba (diff)
downloadcpython-73dbe0461986208564f64e80a7b79264a6a38368.zip
cpython-73dbe0461986208564f64e80a7b79264a6a38368.tar.gz
cpython-73dbe0461986208564f64e80a7b79264a6a38368.tar.bz2
A faulty load_tests in a test module no longer halts test discovery. A placeholder test, that reports the failure, is created instead.
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/loader.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index c04de06..4036454 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -33,12 +33,18 @@ def _make_failed_import_test(name, suiteClass):
# Python 2.3 compatibility
# format_exc returns two frames of discover.py as well
message += '\n%s' % traceback.format_exc()
+ return _make_failed_test('ModuleImportFailure', name, suiteClass,
+ ImportError(message))
- def testImportFailure(self):
- raise ImportError(message)
- attrs = {name: testImportFailure}
- ModuleImportFailure = type('ModuleImportFailure', (case.TestCase,), attrs)
- return suiteClass((ModuleImportFailure(name),))
+def _make_failed_load_tests(name, exception, suiteClass):
+ return _make_failed_test('LoadTestsFailure', name, suiteClass, exception)
+
+def _make_failed_test(classname, methodname, suiteClass, exception):
+ def testFailure(self):
+ raise exception
+ attrs = {methodname: testFailure}
+ TestClass = type(classname, (case.TestCase,), attrs)
+ return suiteClass((TestClass(methodname),))
class TestLoader(object):
@@ -73,7 +79,11 @@ class TestLoader(object):
load_tests = getattr(module, 'load_tests', None)
tests = self.suiteClass(tests)
if use_load_tests and load_tests is not None:
- return load_tests(self, tests, None)
+ try:
+ return load_tests(self, tests, None)
+ except Exception, e:
+ return _make_failed_load_tests(module.__name__, e,
+ self.suiteClass)
return tests
def loadTestsFromName(self, name, module=None):
@@ -239,7 +249,11 @@ class TestLoader(object):
for test in self._find_tests(full_path, pattern):
yield test
else:
- yield load_tests(self, tests, pattern)
+ try:
+ yield load_tests(self, tests, pattern)
+ except Exception, e:
+ yield _make_failed_load_tests(package.__name__, e,
+ self.suiteClass)
defaultTestLoader = TestLoader()