              with self.assertWarns(CacheKeyWarning) as cm:
                  cache.set(key, 'value')
          finally:
              cache.key_func = old_func
  
      def test_invalid_key_characters(self):
          # memcached doesn't allow whitespace or control characters in keys.
 
</s> remove             with self.assertWarnsMessage(CacheKeyWarning, expected_warning):
 </s> add             with self.assertWarns(CacheKeyWarning) as cm: </s> remove         with self.assertRaisesMessage(InvalidCacheKey, msg):
 </s> add         with self.assertRaises(InvalidCacheKey) as cm: </s> remove                 'used with memcached: %r' % key, CacheKeyWarning
 </s> add                 'used with memcached: %r' % key
            self.assertEqual(str(cm.warning), expected_warning)
              with self.assertWarns(CacheKeyWarning) as cm:
                  cache.set(key, 'value')
            self.assertEqual(str(cm.warning), expected_warning)
          finally:
              cache.key_func = old_func
  
      def test_invalid_key_characters(self):
          # memcached doesn't allow whitespace or control characters in keys.
keep add keep keep keep keep keep
 Fixed #31654 -- Fixed cache key validation messages. 
tests/cache/tests.py