I am creating unit tests and I have a test case where the output is expected to be an empty numpy array. I have a second test case where I test the other expected array which has elements.
class myTests(unittest.TestCase):
def test_function(self):
var = 0
result = myFunction(var)
self.assertEqual(np.array([], dtype=np.int64), result)
AssertionError: array([], dtype=int64) != array([], dtype=int64)
I have a feeling it's because they are both empty but I'm not sure. How should I do this test instead?
I ran a debugger to compare the two variables and this is what I got.
result
array([], dtype=int64)
special variables
[0:0] :[]
dtype:dtype('int64')
max:'array is empty'
min:'array is empty'
shape:(0,)
size:0
np.array([], dtype=np.int64)
array([], dtype=int64)
special variables
[0:0] :[]
dtype:dtype('int64')
max:'array is empty'
min:'array is empty'
shape:(0,)
size:0
numpytesting module or utility that has 'assertions' that are suitable for testing arrays. As you see here, the regular Python assertions are not numpy aware.