[Python-Dev] Unit testing (again)

Andrew Kuchling akuchlin@mems-exchange.org
Tue, 13 Feb 2001 12:29:35 -0500


On Tue, Feb 13, 2001 at 12:29:35AM -0500, Jeremy Hylton wrote:
>I hope it's simple disagreement and not arrogance.  I do not agree

I trust not. :) My primary concern is that the tests are quickly
readable, because they're also a form of documentation (hopefully not
the only one though).  I have enough problems debugging the actual
code without having to debug a test suite.

Consider the example Chris posted, which features the snippet:

    def testGetItemFails(self):
        self.assertRaises(KeyError, self._getitemfail)

    def _getitemfail(self):
        return self.t[1]

I don't think this form, requiring an additional small helper method,
is any clearer than self.test_exc('self.t[1]', KeyError); two extra
lines and the loss of locality.  Put tests for 3 or 4 different
exceptions into testGetItemFails and you'd have several helper
functions to trace through.

For simple value tests, this is less important; the difference between
test_val( 'self.db.get_user("FOO")', None ) and test_val(None,
self.db.get_user, "foo") is less.

/F's observation that doctest seems suitable for his work is
interesting and surprising; I'll spend some more time looking at it.

--amk