unittest vs py.test?

Raymond Hettinger vze4rx4y at verizon.net
Fri Apr 1 19:27:39 EST 2005


[Peter Hansen]
> unittest can really be rather light.  Most of our
> test cases are variations on the following, with
> primarily application-specific code added rather than
> boilerplate or other unittest-related stuff:
>
> import unittest
>
> class TestCase(unittest.TestCase):
>      def test01(self):
>          '''some test....'''
>          self.assertEquals(a, b)
>
>      def test02(self):
>          '''another test'''
>          self.assertRaises(Error, func, args)
 . . .
> I'm a little puzzled why folks so often consider this
> particularly "heavy".

unittest never felt heavy to me until I used py.test.  Only then do you realize
how much boilerplate is needed with unittest.  Also, the whole py.test approach
has a much simpler object model.

BTW, the above code simplifies to:

from py.test import raises
assert a == b
raises(Error, func, args)


Raymond Hettinger





More information about the Python-list mailing list