Closed jlleblanc closed 7 months ago
Update: we have since upgraded to the latest version of fakeredis
: 2.20.1. But still encountering this issue during unit testing.
Another update: rather than try to get to the bottom of the Redis issues, I am looking at skipping the cache while in test mode. I am using WAFFLE_READ_FROM_WRITE_DB = True
in settings.py, but this does not have any effect.
I am beginning to think my custom Flag
model is either missing a function, or has a function that is written incorrectly. Has anyone else run into anything like this?
Resolution: I am patching django_redis.cache.RedisCache.delete_many
:
from unittest.mock import patch
# ..
# ..
@patch("django_redis.cache.RedisCache.delete_many")
def test_name_goes_here(self, mock_redis_delete_many):
mock_redis_delete_many.return_value = None # Mock the delete_many call to return None
with override_flag("myFeatureFlag", active=True):
# test itself went here
Hello there, I have created a custom model for my feature flag with Django Waffle 4.1.0. I am needing to flag features by company, which is coincidentally the same example as the one in the custom model documentation. So I am running that code.
Everything seems to be working: I am able to turn flags on and off, limit them by company, limit them by user, and also force them on or off for everyone. I am ultimately delivering flags though an endpoint to the client and this is working.
However, the tests are not working. I first attempted to create my own factory for feature flags, then called that factory in my tests:
But when I try to run the test, it fails on that line. As I go through the stack trace, the last line within Waffle is this one:
The error is ultimately occurs here:
We are using
fakeredis
version1.4.1
in our tests elsewhere without a problem (although we will be upgrading that eventually).I tried using the
override_flag
helper fromwaffle.testutils
, but that also failed in theflush
function of Waffle:I searched the
FakeRedis
repository just now fordelete_many
and nothing turns up for any version in the history of the project.Assuming everything else is okay, is there a way for me to override
flush
just during testing to be no-op?