I've got functions, which sometimes return NaNs with float('nan')
(I'm not using numpy).
How do I write a test for it, since
assertEqual(nan_value, float('nan'))
is just like float('nan') == float('nan')
always false. Is there maybe something like assertIsNan
? I could not find anything about it…
I came up with
math.isnan(x)
will raise aTypeError
ifx
is neither afloat
nor aReal
.It's better to use something like this :
You can then use
self.assertIsNaN()
andself.assertIsNotNaN()
.