title: Django Pytest Test URL Based on Settings
body: <p>I have an endpoint <code>/docs</code> in django that I only want to be visible when <code>DEBUG = True</code> in settings - otherwise, it should throw a 404. My setup looks like this</p>
  
  <p>urls.py</p>
  
  <pre><code>urlpatterns = ...
  
  if settings.DEBUG:
      urlpatterns += [
              url(r'^docs/$', SwaggerSchemaView.as_view(), name='api_docs'),
      ]
  </code></pre>
  
  <p>When doing testing, though, django doesn't automatically reload <code>urls.py</code>, which means simply overriding <code>DEBUG</code> to <code>True</code> or <code>False</code> doesn't work.</p>
  
  <p>My tests look something like this</p>
  
  <pre><code>@override_settings(DEBUG=True)
  @override_settings(ROOT_URLCONF='config.urls')
  class APIDocsTestWithDebug(APITestCase):
      # check for 200s
      ...
  
  @override_settings(DEBUG=False)
  @override_settings(ROOT_URLCONF='config.urls')
  class APIDocsTestWithoutDebug(APITestCase):
      # check for 404s
      ...
  </code></pre>
  
  <p>Now here's the weird part: When I run the tests individually using <code>pytest path/to/test.py::APIDocsTestWithDebug</code> and <code>pytest path/to/test.py::APIDocsTestWithoutDebug</code>, both tests pass. However, if I run the test file as a whole (<code>pytest path/to/test.py</code>), <code>APIDocsTestWithDebug</code> always fails. The fact that <em>they work individually</em> but not together tells me that the <em>url override is working</em>, but when the tests are in tandem, there is some bug that messes things up. I was wondering if anybody had come across a similar issue and either has an entirely different solution or can give me some tips as to what I'm doing wrong.</p>