[Python-Dev] Unit testing (again)
Michel Pelletier
michel@digicool.com
Tue, 13 Feb 2001 14:39:52 -0800 (PST)
On Tue, 13 Feb 2001, Andrew Kuchling wrote:
> 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.
I'm not sure what the purpose of using a unit test to test a different
unit in the same suite is. I've never used assertRaises in this way, and
the small helper method seems just to illustrate your point, not an
often used feature of asserting an Exception condition. More often the
method you are checking for an exception comes from the thing you are
testing, not the test. Maybe you have different usage patterns than I...
-Michel