[Python-checkins] r54208 - python/branches/release25-maint/Lib/unittest.py

georg.brandl python-checkins at python.org
Wed Mar 7 12:55:27 CET 2007


Author: georg.brandl
Date: Wed Mar  7 12:55:25 2007
New Revision: 54208

Modified:
   python/branches/release25-maint/Lib/unittest.py
Log:
backport rev. 54207: add a few sanity checks in unittest.TestSuite.addTest(s).


Modified: python/branches/release25-maint/Lib/unittest.py
==============================================================================
--- python/branches/release25-maint/Lib/unittest.py	(original)
+++ python/branches/release25-maint/Lib/unittest.py	Wed Mar  7 12:55:25 2007
@@ -411,9 +411,18 @@
         return cases
 
     def addTest(self, test):
+        # sanity checks
+        if not callable(test):
+            raise TypeError("the test to add must be callable")
+        if (isinstance(test, (type, types.ClassType)) and
+            issubclass(test, (TestCase, TestSuite))):
+            raise TypeError("TestCases and TestSuites must be instantiated "
+                            "before passing them to addTest()")
         self._tests.append(test)
 
     def addTests(self, tests):
+        if isinstance(tests, basestring):
+            raise TypeError("tests must be an iterable of tests, not a string")
         for test in tests:
             self.addTest(test)
 


More information about the Python-checkins mailing list