Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- my_project.connections.redis.py
- """
- from redis import Redis
- redis_client = Redis()
- """
- my_project.connections.__init__.py
- """
- from my_project.connections.redis import redis_client
- """
- my_project.[all_other_modules].py
- """
- from my_project.connections import redis_client
- redis_client.set( ... )
- """
- In connections.[some_connection].py I set up connections to external stuff, like redis. Then I expose them to all the other modules through `connections`. I guess the reason I do this is that it looks clean and I can easily maintain whatever is inside the [some_connection].py modules.
- However - when I now write integration tests and want to replace Redis with FakeRedis, I can't for the life of me figure out how to patch it....
- Is this even possible?
- I've looked at so many examples of using unittest.mock.patch and/or monkeypatch, but however I try to patch using different namespace combinations, I can't get i working correctly.
- Preliminary conclusion is that the way I'm sharing the redis instance between modules is wrong and should be changed, but I don't know the best way to change it...
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement