[Pyunit-interest] PATCH: AssertionError message
Brought to you by:
purcell
From: Alexander G. <al...@in...> - 2002-06-03 16:46:22
|
I do alot of text manipulation using python and testing with PyUnit, so many of my tests are of the sort: self.assertEqual(string1, string2), and it matters if there is a space on the end of one string and not on the other. So when PyUnit returns an error message which does not delimit the strings, I lose time trying to figure out where the difference between these seemingly similar 200+ character strings is, when the only difference is an extra space on the end of one. So I hacked unittest.py as per the following patch. Now when strings are not equal, they are displayed in quotes, so I can tell exactly where the strings begin and end. I am rather a newbie, so don't know if this will break anything. It could be made conditional to strings easily enough. Something like: if type(first) == types.StringType: first = repr(first) would work, I suppose. It seemed useful and generic enough to me to suggest it for inclusion. Feel free to beat me up for stupidity. :) Alexander --- pyunit-1.4.1/unittest.py Wed Aug 8 02:05:08 2001 +++ my_pyunit/unittest.py Mon Jun 3 11:23:03 2002 @@ -270,14 +270,14 @@ operator. """ if first != second: - raise self.failureException, (msg or '%s != %s' % (first, second)) + raise self.failureException, (msg or '%s != %s' % ( repr(first), repr(second) )) def failIfEqual(self, first, second, msg=None): """Fail if the two objects are equal as determined by the '==' operator. """ if first == second: - raise self.failureException, (msg or '%s == %s' % (first, second)) + raise self.failureException, (msg or '%s == %s' % ( repr(first), repr(second) )) assertEqual = assertEquals = failUnlessEqual |