title: How to mock redis for Django tests
body: <p>I am trying to mock out redis in my Django application. I have tried several different methods but none seem to work. What am I doing wrong?</p>
  
  <p>My primary redis instance is called with: </p>
  
  <pre><code>redis_client = redis.from_url(os.environ.get("REDIS_URL"))
  </code></pre>
  
  <p>That instance is imported in other parts of the app in order to add and retrieve data.</p>
  
  <p>In my tests I tried doing:</p>
  
  <pre><code>import fakeredis
  from mock import patch
  
  class TestViews(TestCase):
      def setUp(self):
          redis_patcher = patch('redis.Redis', fakeredis.FakeRedis)
          self.redis = redis_patcher.start()
  
          self.redis.set('UPDATE', 'Spring')
          print(redis_client.get('UPDATE'))
  
      def tearDown(self):
          self.redis_patcher.stop
  </code></pre>
  
  <p>When running the tests I want the 'UPDATE' variable to be set. But instead every instance of redis_client fails saying the server is not available. How can I mock out redis and set values, so that they are available when testing my app?</p>