New submission from Jay Moorthi <[email protected]>:
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.
----------
messages: 123745
nosy: Jay.Moorthi
priority: normal
severity: normal
status: open
title: unittest should have an assertChanges context manager
type: feature request
versions: Python 2.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue10675>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com