title: How to mock a redis client in Python?
body: <p>I just found that a bunch of unit tests are failing, due a developer hasn't mocked out the dependency to a redis client within the test. I'm trying to give a hand in this matter but have difficulties myself.</p>
  
  <p>The method writes to a redis client:</p>
  
  <pre><code>redis_client = get_redis_client()
  redis_client.set('temp-facility-data', cPickle.dumps(df))
  </code></pre>
  
  <p>Later in the assert the result is retrieved:</p>
  
  <pre><code>res = cPickle.loads(get_redis_client().get('temp-facility-data'))
  expected = pd.Series([set([1, 2, 3, 4, 5])], index=[1])
  assert_series_equal(res.variation_pks, expected)
  </code></pre>
  
  <p>I managed to patch the redis client's get() and set() successfully.</p>
  
  <pre><code>@mock.patch('redis.StrictRedis.get')
  @mock.patch('redis.StrictRedis.set')
  def test_identical(self, mock_redis_set, mock_redis_get):
      mock_redis_get.return_value = ???
      f2 = deepcopy(self.f)
      f3 = deepcopy(self.f)
      f2.pk = 2
      f3.pk = 3
      self.one_row(f2, f3)
  </code></pre>
  
  <p>but I don't know how to set the <code>return_value</code> of <code>get()</code> to what the <code>set()</code> would set in the code, so that the test would pass.</p>
  
  <p>Right now this line fails the test:</p>
  
  <pre><code>res = cPickle.loads(get_redis_client().get('temp-facility-data'))
  TypeError: must be string, not MagicMock
  </code></pre>
  
  <p>Any advice please?</p>