Use 'assertIs' to check literal booleans in Python unittest
I used to use Unittest's self.assertTrue / self.assertFalse to check both literal booleans and truthy/falsy values in Unittest. Committed the same sin while writing tests in Django.
I feel like assertTrue and assertFalse are misnomers. They don't specifically check literal booleans, only truthy and falsy states respectively.
Consider this example:
In the above snippet, I've used assertTrue and assertFalse to check both literal booleans and truthy/falsy values. However, to test the literal boolean values, assertIs works better and is more explicit. Here's how to do the above test properly:
Notice how I've used self.assertIs in the is_true and is_false methods to explicitly test out the literal boolean values. The is_truthy and is_falsy methods were kept unchanged from the previous snippet.
Further reading
Discussion in the ATmosphere