Comments (8)
Hi, can you please post the full test code? I think you are using fakeredis incorrectly.
You should not override Redis
, but create a connection using FakeRedis
instead of Redis
See How to use section.
from fakeredis-py.
@cunla: I am using FakeRedis for unit tests. Since the code that creates the Redis connection is part of what's being tested, I'm using unittest.mock.patch()
to replace the call to redis.Redis()
with fakeredis.FakeRedis()
.
from fakeredis-py.
Can you post a sample test that fails here? I suspect (though not sure) you are patching in the wrong place.
Notice FakeRedis
inherits from Redis
so it might cause a circular dependency.
from fakeredis-py.
from fakeredis-py.
@cunla I can't give you the original code due to company policy. However, it looks something like this:
foo.py
:
from redis import Redis
def connect_redis(redis_host: str, redis_port: int) -> Redis:
redis_con = Redis(redis_host, redis_port)
...
return redis_con
def bar(zip, zap):
...
redis_con = connect_redis(redis_host, redis_port)
...
test_foo.py
:
from unittest.mock import patch
from fakeredis import FakeRedis
...
def test_bar():
# Mock Redis connection
with patch('foo.Redis', FakeRedis):
# Call function
bar(zip, zap)
# Check the data in Redis is as expected
...
from fakeredis-py.
I use a very similar pattern (monkeypatch redis.Redis with FakeRedis for testing purposes) and can confirm this bug.
FakeRedis 1.7.1 works fine, anything after is broken.
OS: Debian Bullseye, CentOS 7
Python version: 3.9.2
redis-py version: 4.3.4
fakeredis version: 1.8.1
from fakeredis-py.
Trying today
from fakeredis-py.
Fix in 1.8.2
from fakeredis-py.
Related Issues (20)
- Implement support for `TOPK.INCRBY` (topk command)
- Implement support for `TOPK.QUERY` (topk command)
- Implement support for `TOPK.COUNT` (topk command)
- Implement support for `TOPK.LIST` (topk command)
- Implement support for `TOPK.INFO` (topk command)
- Using a blocking XREAD on an empty stream returns a list instead of blocking HOT 1
- EXAT option does not work HOT 1
- The documentation for adding `FakeRedis` as a cache backend in Django is outdated.
- Add support for specifying specific Lua runtime version HOT 12
- Support for floating point timeout values HOT 1
- FastAPI integration Async Redis session dependency override, error during test RuntimeError: <Queue > is bound to a different event loop HOT 18
- FakeAsyncRedis stores state when clear instance expected. HOT 4
- xinfo_stream returns data for a stream that doesn't exist HOT 1
- Data persistence for sync and async clients is surprisingly different
- `FakeRedis.smembers()` reads data added to other instances (in version 2.21.2) HOT 4
- Persistence between across pytest cases difference between 2.21.1 and 2.21.2 HOT 10
- Type hint for version doesn't permit what the docs say to do HOT 3
- Add better support for LUA scripts HOT 25
- Mismatch in outputs of blocking XREAD in Fake vs Real redis libraries HOT 1
- Reading multiple streams does not give expected result HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fakeredis-py.