summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-07 11:55:25 +0000
committerGeorg Brandl <georg@python.org>2007-03-07 11:55:25 +0000
commitd480b3370b8015dbe0f217b49c9e18b5c986d28e (patch)
tree9303cd1db1fa6eedae30c81222c03c2e683468c8
parent4a7da9cdbc2100e5b6c8b6d9da58ee8f5a813a96 (diff)
downloadcpython-git-d480b3370b8015dbe0f217b49c9e18b5c986d28e.tar.gz
backport rev. 54207: add a few sanity checks in unittest.TestSuite.addTest(s).
-rw-r--r--Lib/unittest.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py
index cde23d8a08..cd91c2c5b1 100644
--- a/Lib/unittest.py
+++ b/Lib/unittest.py
@@ -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)