How to mock django settings attribute used in another module?
<p>Lets say module <code>a</code> code:</p>

<pre><code>from django.conf import settings
print settings.BASE_URL # prints http://example.com
</code></pre>

<p>In <code>tests.py</code> I want to mock the <code>BASE_URL</code> to <code>http://localhost</code></p>

<p>I have tried the following:</p>

<pre><code>with mock.patch('django.conf.settings.BASE_URL', 'http://localhost'):
    pass

with mock.patch('a.settings.BASE_URL', 'http://localhost'):
    pass

from a import settings

with mock.patch.object(settings, 'BASE_URL', 'http://localhost'):
    pass

import a

with mock.patch.object(a.settings, 'BASE_URL', 'http://localhost'):
    pass
</code></pre>

<p>None of the above worked.</p>