这是我的缓存设置:
ENABLE_CACHING = True
if ENABLE_CACHING:
CACHES = get_cache()
else:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
我尝试以两种方式覆盖此设置:
@override_settings(ENABLE_CACHING=False)
@override_settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}})
class IndexViewTests(TestCase):
def test_index_view_with_a_future_question(self):
"""
Questions with a pub_date in the future should not be displayed on
the index page.
"""
create_question('Future question', 1,
[Choice(choice_text='Dummy choice')])
response = self.client.get(reverse('polls:index'))
self.assertEqual(response.status_code, 200)
self.assertQuerysetEqual(response.context['latest_questions'], [])
self.assertEqual(response.context['total_questions'], 1)
self.assertEqual(response.context['total_votes'], 0)
两者都不会覆盖设置,我必须再次手动完成。怎么解决这个问题? 这是由启用的缓存导致的测试结果失败示例:
ERROR: test_index_view_with_a_future_question (polls.tests.IndexViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/david/Projects/easypolls/polls/tests.py", line 375, in test_index_view_with_a_future_question
self.assertQuerysetEqual(response.context['latest_questions'], [])
TypeError: 'NoneType' object is not subscriptable