testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00437
[Merge] lp:~jelmer/testtools/assertIsInstance-msg into lp:testtools
Jelmer Vernooij has proposed merging lp:~jelmer/testtools/assertIsInstance-msg into lp:testtools.
Requested reviews:
testtools developers (testtools-dev)
Related bugs:
#689149 TestCase.assertIsInstance doesn't take optional msg
https://bugs.launchpad.net/bugs/689149
Add an optional "msg" argument for overriding the message to TestCase.assertIsInstance, for compatibility with Python 2.7's TestCase.assertDictEqual.
--
https://code.launchpad.net/~jelmer/testtools/assertIsInstance-msg/+merge/43458
Your team testtools developers is requested to review the proposed merge of lp:~jelmer/testtools/assertIsInstance-msg into lp:testtools.
=== modified file 'testtools/testcase.py'
--- testtools/testcase.py 2010-11-27 10:51:14 +0000
+++ testtools/testcase.py 2010-12-12 04:13:52 +0000
@@ -300,10 +300,11 @@
self.assertTrue(
needle not in haystack, '%r in %r' % (needle, haystack))
- def assertIsInstance(self, obj, klass):
- self.assertTrue(
- isinstance(obj, klass),
- '%r is not an instance of %s' % (obj, self._formatTypes(klass)))
+ def assertIsInstance(self, obj, klass, msg=None):
+ if msg is None:
+ msg = '%r is not an instance of %s' % (
+ obj, self._formatTypes(klass))
+ self.assertTrue(isinstance(obj, klass), msg)
def assertRaises(self, excClass, callableObj, *args, **kwargs):
"""Fail unless an exception of class excClass is thrown
=== modified file 'testtools/tests/test_testtools.py'
--- testtools/tests/test_testtools.py 2010-11-11 09:46:18 +0000
+++ testtools/tests/test_testtools.py 2010-12-12 04:13:52 +0000
@@ -375,6 +375,16 @@
'42 is not an instance of %s' % self._formatTypes([Foo, Bar]),
self.assertIsInstance, 42, (Foo, Bar))
+ def test_assertIsInstance_overridden_message(self):
+ # assertIsInstance(obj, klass, msg) fails the test with the specified
+ # message when obj is not an instance of klass.
+
+ class Foo(object):
+ """Simple class for testing assertIsInstance."""
+
+ self.assertFails("Bericht",
+ self.assertIsInstance, 42, Foo, "Bericht")
+
def test_assertIs(self):
# assertIs asserts that an object is identical to another object.
self.assertIs(None, None)
Follow ups