It's useful to use the findTestCases utility function to find all the test cases in the current
module, instead of makeSuite'ing each test case manually. For example, instead of:
import unittest
class TestProxyBase(unittest.TestCase):
def _makeOne(self, id, resource):
from Products.davproxy.resource import ProxyBase
return ProxyBase(id, resource)
def test_getId(self):
p = self._makeOne('theid', None)
self.assertEqual(p.getId(), 'theid')
def test_getId_utf8(self):
p = self._makeOne(u'dummytitle-\u03cb', None)
self.assertEqual(p.getId().decode('utf-8'), u'dummytitle-\u03cb')
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestProxyBase),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
I really want do do this, so I don't have to keep adding stuff to "test_suite" when I add more test cases to the module:
import unittest
class TestProxyBase(unittest.TestCase):
def _makeOne(self, id, resource):
from Products.davproxy.resource import ProxyBase
return ProxyBase(id, resource)
def test_getId(self):
p = self._makeOne('theid', None)
self.assertEqual(p.getId(), 'theid')
def test_getId_utf8(self):
p = self._makeOne(u'dummytitle-\u03cb', None)
self.assertEqual(p.getId().decode('utf-8'), u'dummytitle-\u03cb')
def test_suite():
import sys
return unittest.findTestCases(sys.modules[__name__])
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
http://docs.python.org/lib/unittest-contents.html