Pickle can't store an object in django locmem cache during tests?

前端 未结 4 441
天命终不由人
天命终不由人 2021-01-25 02:27

Something that\'s puzzling me a bit...

>>> from django.core.cache import get_cache
>>>
>>> cache = get_cache(\'django.core.cache.backe         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-25 03:02

    WIth help from Martijn in this follow-up question it turns out the short answer is:

    "Yup".

    You can't pickle Mock() objects as they do not provide the top-level object that they are mocking so pickle therefore has no idea where to import from. As the cache requires the object to be pickled to store it, it is not possible to store a Mock() instance in the LocMemCache. Will have to rethink how I go about testing this.

提交回复
热议问题