This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jay.Moorthi
Recipients Jay.Moorthi
Date 2010-12-10.19:58:34
SpamBayes Score 1.1051182e-10
Marked as misclassified No
Message-id <1292011116.36.0.95630190465.issue10675@psf.upfronthosting.co.za>
In-reply-to
Content
It would be useful to have a new assert method in the unittest.TestCase class that checks to see if a value has changed.  I wrote a quick and dirty version like so:

class MySpecialTestCase(unittest.TestCase):
    @contextmanager
    def assertChanges(self, thing, attr=None, by=None):
        def get_value(thing, attr):
            if callable(thing):
                value = thing()
            else:
                value = getattr(thing, attr)
            return value

        old_value = get_value(thing, attr)
        yield
        new_value = get_value(thing, attr)

        if by is None:
            self.assertNotEqual(new_value, old_value)
        else:
            self.assertEqual(new_value - old_value, by)

I'm sure something better can be done to take better advantage of the unittest module's diffing tools, etc.
History
Date User Action Args
2010-12-10 19:58:36Jay.Moorthisetrecipients: + Jay.Moorthi
2010-12-10 19:58:36Jay.Moorthisetmessageid: <1292011116.36.0.95630190465.issue10675@psf.upfronthosting.co.za>
2010-12-10 19:58:34Jay.Moorthilinkissue10675 messages
2010-12-10 19:58:34Jay.Moorthicreate