Unittest testing assert*() calls rather than methods?

Tim Chase python.list at tim.thechases.com
Wed Sep 28 16:16:59 CEST 2011


While I asked this on the Django list as it happened to be with 
some Django testing code, this might be a more generic Python 
question so I'll ask here too.

When performing unittest tests, I have a number of methods of the 
form

   def test_foo(self):
     data = (
       (item1, result1),
       ... #bunch of tests for fence-post errors
       )
     for test, result in data:
       self.assertEqual(process(test), result)

When I run my tests, I only get a tick for running one the one 
test (test_foo), not the len(data) tests that were actually 
performed.  Is there a way for unittesting to report the number 
of passed-assertions rather than the number of test-methods run?

-tkc





More information about the Python-list mailing list