def test_13_cache_username(self): self.counter = 0 def get_username(uid, resolver): self.counter += 1 return "user1" r = cache_username(get_username, "uid1", "reso1") self.assertEqual(r, "user1") self.assertEqual(self.counter, 1) # The second call does not increase the counter, since the result is fetched from the cache r = cache_username(get_username, "uid1", "reso1") self.assertEqual(r, "user1") self.assertEqual(self.counter, 1)