id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 21518,override_settings(ROOT_URLCONF) doesn't clear resolver cache,Chris Wilson,Chris Wilson,"If override_settings is used to set different URL mappings on different tests, by setting ROOT_URLCONF to different values, it doesn't work properly because the resolver cache is never cleared. You might argue that this behaviour is unnecessary or broken, but Django-CMS for example [http://docs.django-cms.org/en/2.4.2/extending_cms/testing.html recommends that you do]: Your apps need testing, but in your live site they aren’t in urls.py as they are attached to a CMS page. So if you want to be able to use reverse() in your tests, or test templates that use the url template tag, you need to hook up your app to a special test version of urls.py and tell your tests to use that... in your tests you can plug this in with the override_settings() decorator. A simple test case that fails: {{{#!python class FirstUrls: urlpatterns = patterns('', url(r'first/$', fake_view, name='first')) class SecondUrls: urlpatterns = patterns('', url(r'second/$', fake_view, name='second')) class OverrideSettingsTests(TestCase): """""" If neither override_settings nor a settings_changed receiver clears the URL cache between tests, then one of these two test methods will fail. """""" @override_settings(ROOT_URLCONF=FirstUrls) def test_first(self): reverse('first') @override_settings(ROOT_URLCONF=SecondUrls) def test_second(self): reverse('second') }}} In order for this to work, I think the best approach is to add another listener for the `settings_changed` signal in `django/test/signals.py`, which detects when the `ROOT_URLCONF` setting is changed and clears the LRU caches in `django.core.urlresolvers`. ",Bug,closed,Core (URLs),1.6,Normal,fixed,,,Accepted,1,0,0,0,0,0