[Python-Dev] Unittest PEP do's and don'ts (BDFL pronouncement)

Georg Brandl g.brandl at gmx.net
Wed Jul 16 23:46:46 CEST 2008


C. Titus Brown schrieb:

> Sorry for the second message, but... let's compare:
> 
> test_sort.py:
>  #! /usr/bin/env python
>  import unittest
>  class Test(unittest.TestCase):
>   def test_me(self):
>      seq = [ 5, 4, 1, 3, 2 ]
>      seq.sort()
>      self.assertEqual(seq, [1, 2, 3, 4, 5])
> 
>  if __name__ == '__main__':
>     unittest.main()
> 
> with
> 
> test_sort2.py :
> 
>  def test_me():
>     seq = [ 5, 4, 1, 3 2 ]
>     seq.sort()
>     assert seq == [1, 2, 3, 4, 5]
> 
> The *only value* that unittest adds here is in the 'assertEqual'
> statement, which (I think) returns a richer error message than 'assert'.

If you use py.test, it does some magic to find out your test is an
equality comparison and displays both operands' repr().  Don't know about
nose.

Georg



More information about the Python-Dev mailing list