Giter Club home page Giter Club logo

Comments (8)

cunla avatar cunla commented on August 16, 2024

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.

macdjord avatar macdjord commented on August 16, 2024

@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.

cunla avatar cunla commented on August 16, 2024

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.

cunla avatar cunla commented on August 16, 2024

@macdjord ?

from fakeredis-py.

macdjord avatar macdjord commented on August 16, 2024

@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.

whoiswes avatar whoiswes commented on August 16, 2024

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.

cunla avatar cunla commented on August 16, 2024

Trying today

from fakeredis-py.

cunla avatar cunla commented on August 16, 2024

Fix in 1.8.2

from fakeredis-py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.