Python/Django: how to assert that unit test result contains a certain string?

To assert if a string is or is not a substring of another, you should use assertIn and assertNotIn:

# Passes
self.assertIn('bcd', 'abcde')

# AssertionError: 'bcd' unexpectedly found in 'abcde'
self.assertNotIn('bcd', 'abcde')

These are new since Python 2.7 and Python 3.1

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)