summaryrefslogtreecommitdiff
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2011-01-03 17:00:11 +0000
committerMichael Foord <fuzzyman@voidspace.org.uk>2011-01-03 17:00:11 +0000
commit753634c0dfe40fb1423797a1dc28f3e391dc88fc (patch)
tree323e304e64ecd705fefe2a2619038c8237fa829c /Lib/unittest
parent6ce3cde9f237c0fb7ff514d7d9a2d0b9518494d8 (diff)
downloadcpython-753634c0dfe40fb1423797a1dc28f3e391dc88fc.tar.gz
Enable unittest.TestCase to be instantiated without providing a method name.
Changed unittestgui to show number of discovered tests in the status bar.
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py11
-rw-r--r--Lib/unittest/test/test_case.py10
2 files changed, 18 insertions, 3 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 004a9f5d33..0277ac861c 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -274,12 +274,17 @@ class TestCase(object):
"""
self._testMethodName = methodName
self._outcomeForDoCleanups = None
+ self._testMethodDoc = 'No test'
try:
testMethod = getattr(self, methodName)
except AttributeError:
- raise ValueError("no such test method in %s: %s" %
- (self.__class__, methodName))
- self._testMethodDoc = testMethod.__doc__
+ if methodName != 'runTest':
+ # we allow instantiation with no explicit method name
+ # but not an *incorrect* or missing method name
+ raise ValueError("no such test method in %s: %s" %
+ (self.__class__, methodName))
+ else:
+ self._testMethodDoc = testMethod.__doc__
self._cleanups = []
# Map types to custom assertEqual functions that will compare
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 9a09dfaff0..1513fbecb7 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -77,6 +77,16 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
self.assertEqual(Test().id()[-13:], '.Test.runTest')
+ # test that TestCase can be instantiated with no args
+ # primarily for use at the interactive interpreter
+ test = unittest.TestCase()
+ test.assertEqual(3, 3)
+ with test.assertRaises(test.failureException):
+ test.assertEqual(3, 2)
+
+ with self.assertRaises(AttributeError):
+ test.run()
+
# "class TestCase([methodName])"
# ...
# "Each instance of TestCase will run a single test method: the