MCPcopy Index your code
hub / github.com/python/cpython / assertIsInstance

Method assertIsInstance

Lib/unittest/case.py:1329–1337  ·  view source on GitHub ↗

Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.

(self, obj, cls, msg=None)

Source from the content-addressed store, hash-verified

1327 self.fail(self._formatMessage(msg, standardMsg))
1328
1329 def assertIsInstance(self, obj, cls, msg=None):
1330 """Same as self.assertTrue(isinstance(obj, cls)), with a nicer
1331 default message."""
1332 if not isinstance(obj, cls):
1333 if isinstance(cls, tuple):
1334 standardMsg = f'{safe_repr(obj)} is not an instance of any of {cls!r}'
1335 else:
1336 standardMsg = f'{safe_repr(obj)} is not an instance of {cls!r}'
1337 self.fail(self._formatMessage(msg, standardMsg))
1338
1339 def assertNotIsInstance(self, obj, cls, msg=None):
1340 """Included for symmetry with assertIsInstance."""

Calls 3

failMethod · 0.95
_formatMessageMethod · 0.95
safe_reprFunction · 0.85