@memoize def empty_function(): global has_been_called has_been_called = True return 'empty_function' class EcsCacheTest(unittest.TestCase): @memoize def empty_method(self): global has_been_called has_been_called = True return 'empty_method' def test_empty_functions(self): # test with an empty function # first call: we will use the real function self.assertEqual(empty_function(), 'empty_function') self.assertEqual(has_been_called, True) # Second call: we will use the cache self.assertEqual(empty_function(), 'empty_function') self.assertEqual(has_been_called, False) # test with an empty method # first call: we will use the real method self.assertEqual(self.empty_method(), 'empty_method') self.assertEqual(has_been_called, True) # Second call: we will use the cache self.assertEqual(self.empty_method(), 'empty_method') self.assertEqual(has_been_called, False)