I have some code like:
if not settings.VAR_URL: 
    raise Exception("VAR_URL is not defined") 
When I try to test it like:
def test_for_absent_env(self):
    del os.environ['VAR_URL']
    o = Object()
    with self.assertRaises(Exception) as error:
        o.some_function()
        self.assertEqual(error.exception.message, "VAR_URL is not defined")
But it gives KeyError instead of passed test. What should I correct?