https://github.com/dhui/redis-mock-py
Python mock class for the redis-py library
https://github.com/dhui/redis-mock-py
Last synced: 10 months ago
JSON representation
Python mock class for the redis-py library
- Host: GitHub
- URL: https://github.com/dhui/redis-mock-py
- Owner: dhui
- Created: 2011-10-04T21:00:55.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-10-07T07:42:30.000Z (over 14 years ago)
- Last Synced: 2025-03-06T16:42:16.627Z (10 months ago)
- Language: Python
- Homepage:
- Size: 93.8 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
redis-mock-py
A Python mock library for the redis-py client.
Note: This module is not thread safe
Currently only a few Redis sorted set commands are supported (ZADD, ZRANGE, ZRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYSCORE)
I will be adding more commands in the future.
If you want more commands added, send me a message via github (username: dhui).
Usage:
To start using the Redis mock, you'll need to add the following imports:
import mock
import redis_mock
Then in your setUp() function in your unit test class, call:
redis_mock.flush_db()
In any of your test functions that use the redis-py library, add the decorator:
@mock.patch.object(redis.Redis, 'execute_command')
That same test function must take the argument:
mock_execute_command
Inside that same test function, set mock_execute_command's side effect:
mock_execute_command.side_effect = redis_mock.execute_command
Example:
class TestSuite(unittest.TestCase):
def setUp(self):
redis_mock.flush_db()
@mock.patch.object(redis.Redis, 'execute_command')
def simple_test(self, mock_execute_command):
mock_execute_command.side_effect = redis_mock.execute_command