title: How to Unit test with different settings in Django?
body: <p>Is there any simple mechanism for overriding Django settings for a unit test?  I have a manager on one of my models that returns a specific number of the latest objects.  The number of objects it returns is defined by a NUM_LATEST setting.</p>
  
  <p>This has the potential to make my tests fail if someone were to change the setting.  How can I override the settings on <code>setUp()</code> and subsequently restore them on <code>tearDown()</code>?  If that isn't possible, is there some way I can monkey patch the method or mock the settings?</p>
  
  <p><strong>EDIT:</strong> Here is my manager code:</p>
  
  <pre><code>class LatestManager(models.Manager):
      """
      Returns a specific number of the most recent public Articles as defined by 
      the NEWS_LATEST_MAX setting.
      """
      def get_query_set(self):
          num_latest = getattr(settings, 'NEWS_NUM_LATEST', 10)
          return super(LatestManager, self).get_query_set().filter(is_public=True)[:num_latest]
  </code></pre>
  
  <p>The manager uses <code>settings.NEWS_LATEST_MAX</code> to slice the queryset.  The <code>getattr()</code> is simply used to provide a default should the setting not exist.</p>