]> granicus.if.org Git - python/commitdiff
backport rev. 54207: add a few sanity checks in unittest.TestSuite.addTest(s).
authorGeorg Brandl <georg@python.org>
Wed, 7 Mar 2007 11:55:25 +0000 (11:55 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 7 Mar 2007 11:55:25 +0000 (11:55 +0000)
Lib/unittest.py

index cde23d8a083737d30f68a15b83f106b1a5cbf8e9..cd91c2c5b189711954303b28661ad1248cbc2968 100644 (file)
@@ -411,9 +411,18 @@ class TestSuite:
         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)