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

C. Titus Brown ctb at msu.edu
Wed Jul 16 23:20:07 CEST 2008

On Wed, Jul 16, 2008 at 02:15:29PM -0700, C. Titus Brown wrote:
-> At this point I might suggest taking a look at the nose and py.test
-> discovery rules and writing a simple test discovery system to find &
-> wrap 'test_' functions/classes and doctests in a unittest wrapper.
-> Many people use nose and py.test (which use remarkably similar test
-> discovery procedures, note) and the basic algorithm is pretty well
-> worked out.  And, since nose wraps such tests in unittests anyway, it
-> can be made entirely compatible with pre-existing TestRunner
-> derivatives.

Sorry for the second message, but... let's compare:

 #! /usr/bin/env python
 import unittest
 class Test(unittest.TestCase):
  def test_me(self):
     seq = [ 5, 4, 1, 3, 2 ]
     self.assertEqual(seq, [1, 2, 3, 4, 5])

 if __name__ == '__main__':


test_sort2.py :

 def test_me():
    seq = [ 5, 4, 1, 3 2 ]
    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 I could run the second program by doing


I would be a very happy man... right now it requires installing nose or

C. Titus Brown, ctb at msu.edu

More information about the Python-Dev mailing list