I'm trying to mock redis class using mockredis as show below. But the original redis class is not getting masked.
test_hitcount.py
import unittest
from mock import patch
import mockredis
import hitcount
class HitCountTest(unittest.TestCase):
@patch('redis.StrictRedis', mockredis.mock_strict_redis_client)
def testOneHit(self):
# increase the hit count for user peter
hitcount.hit("pr")
# ensure that the hit count for peter is just 1
self.assertEqual(b'0', hitcount.getHit("pr"))
if __name__ == '__main__':
unittest.main()
hitcount.py
import redis
r = redis.StrictRedis(host='0.0.0.0', port=6379, db=0)
def hit(key):
r.incr(key)
def getHit(key):
return (r.get(key))
Where am I making the mistake?
hitcount?