Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
diff --git a/Lib/unittest.py b/Lib/unittest.py
index 83790fc..f99f958 100644
--- a/Lib/unittest.py
+++ b/Lib/unittest.py
@@ -806,6 +806,18 @@
standardMsg = '%r unexpectedly found in %r' % (member, container)
self.fail(self._formatMessage(msg, standardMsg))
+ def assertIs(self, expr1, expr2, msg=None):
+ """Just like self.assertTrue(a is b), but with a nicer default message."""
+ if expr1 is not expr2:
+ standardMsg = '%r is not %r' % (expr1, expr2)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertIsNot(self, expr1, expr2, msg=None):
+ """Just like self.assertTrue(a is not b), but with a nicer default message."""
+ if expr1 is expr2:
+ standardMsg = 'unexpectedly identical: %r' % (expr1,)
+ self.fail(self._formatMessage(msg, standardMsg))
+
def assertDictEqual(self, d1, d2, msg=None):
self.assert_(isinstance(d1, dict), 'First argument is not a dictionary')
self.assert_(isinstance(d2, dict), 'Second argument is not a dictionary')