Why is assertFalsedoing well None?
import unittest
class TestNoneIsFalse(unittest.TestCase):
def test_none_is_false(self):
self.assertFalse(None)
Results:
> python -m unittest temp
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
This behavior seems to cause errors when a function does not always return a value. For example:
def is_lower_than_5(x):
if x < 5:
return True
elif x > 5:
return False
....
def test_5_is_not_lower_than_5(self):
self.assertFalse(is_lower_than_5(5))
The above test would pass, even if it should fail. There is no error in the code.
How can we say that a value is literal False, not just false in a boolean context? eg.
self.assertEquals(False, None)
source
share