Following statement passes in my tests.
self.assertEqual(3.3, np.asarray([3.3]))
One type is numpy.float64
other is numpy.ndarray
and my assumption was that this test will fail but it passes.
Following statement prints [ True]
print(3.3 == np.asarray([3.3]))
Debugging further shows that assertEquals
ends up invoking unittest.case.TestCase#_baseAssertEqual
which checks equality using ==
:
if not first == second:
standardMsg = '%s != %s' % _common_shorten_repr(first, second)
msg = self._formatMessage(msg, standardMsg)
raise self.failureException(msg)
Can someone explain why and how test self.assertEqual(3.3, np.asarray([3.3]))
passes?
Edit: How ==
works in case you compare an array of one value with a variable and where is this behaviour documented?