title: During tests, how to override a Django setting used in the urlconf?
body: <p>In my Django project's urlconf I have something like this:</p>
  
  <pre><code>from django.conf import settings
  from django.conf.urls import include, url
  
  urlpatterns = [
      url(r'^{}/blog'.format(settings.MY_ROOT_DIR),
          include('weblogs.urls')),
      # ...
  ]
  </code></pre>
  
  <p>In my <code>settings.py</code> I'll have something like:</p>
  
  <pre><code>MY_ROOT_DIR = 'phil'
  </code></pre>
  
  <p>This is so I can set the root directory, that's used in several places, in one place (the settings).</p>
  
  <p>When I come to test URLs, I use the <a href="https://docs.djangoproject.com/en/1.11/topics/testing/tools/#django.test.override_settings" rel="nofollow noreferrer"><code>@override_settings</code> decorator</a>:</p>
  
  <pre><code>from django.test import TestCase, override_settings
  from django.urls import reverse
  
  @override_settings(MY_ROOT_DIR='terry')
  class WeblogUrlsTestCase(TestCase):
  
          def test_post_detail_url(self):
              self.assertEqual(
                  reverse('post_detail', kwargs={'slug': 'my-post'}),
                  '/terry/blog/my-post/'
              )
  </code></pre>
  
  <p>However, <code>@override_settings</code> doesn't appear to do anything - the <code>MY_ROOT_DIR</code> value used in <code>urls.py</code> is always <code>"phil"</code>, never the overridden setting of <code>"terry"</code>. I've also tried <code>@modify_settings</code>, and using it on the test method, rather than the class.</p>
  
  <p>I guess the urlconf is is loaded by Django before <code>@override_settings</code> takes effect? Is there a way around this? Or a better solution altogether?</p>