[TIP] new assertion library for unit tests

Pete pfein at pobox.com
Wed Aug 13 07:29:11 PDT 2008


On Aug 13, 2008, at 3:48 AM, Nicolas Chauvat wrote:

> On Wed, Aug 13, 2008 at 05:50:43PM +1200, Michael Gratton wrote:
>>  def testSplit(self):
>>      s = 'foo,bar'
>>      expected = ['foo', 'bar']
>>      actual = s.split(',')
>>      self.assertEqual(len(expected), len(actual),
>>                       'Length of %s expected to equal %s' %
>>                       (expected, len(actual)))
>>      self.assertEqual(expected[0], actual[0])
>>      self.assertEqual(expected[1], actual[1])
>
> With logilab.common.testlib, that's
>
> self.assertListEquals(expected, actual)
>
> And you get a detailed error explaining what differs in case the lists
> don't match.

Internally, I have an assert_sorted_equals function.

But yeah, better list/dict/set test comparison funcs in unittest would  
be nice.  Do I smell a PEP?

--Pete



More information about the testing-in-python mailing list